Re: does C# have any collection objects that support sort functionality so that I dont have to write my own sorting algorithm?
- From: "Kai Brinkmann [MSFT]" <kaibrink@xxxxxxxxxxxxxxxxxxxx>
- Date: Fri, 5 Aug 2005 12:09:40 -0700
Keep in mind, though, that the objects in the collection have to implement
the IComparable interface. That's true for both the Array and ArrayList
classes. The system data types (including strings) implement this interface.
But if you are looking to sort custom objects you created, you need to make
sure to implement it yourself.
Also, since arrays are strongly typed, you know that all elements are of the
same type and should be comparable. However, that's not necessarily the case
for ArrayLists. So you need to be careful what you store in these types of
collections. The Sort() method will utilize each object's IComparable
implementation (regardless of the type), so be sure that a meaningful
comparison is possible.
--
Kai Brinkmann [MSFT]
Please do not send e-mail directly to this alias. This alias is for
newsgroup purposes only.
This posting is provided "AS IS" with no warranties, and confers no rights.
"Jon Shemitz" <jon@xxxxxxxxxxxxxxxxx> wrote in message
news:42F3B5D4.BF1CEA64@xxxxxxxxxxxxxxxxxxxx
> Daniel wrote:
>>
>> does C# have any collection objects that support sort functionality so
>> that
>> I dont have to write my own sorting algorithm?
>
> Of course. You can sort arrays, you can sort the ArrayList class, you
> can sort the generic List<T>, &c.
>
> --
>
> www.midnightbeach.com
.
- References:
- Prev by Date: RE: ToolTip
- Next by Date: Rows.Add and CurrencyManager
- Previous by thread: Re: does C# have any collection objects that support sort functionality so that I dont have to write my own sorting algorithm?
- Next by thread: Re: does C# have any collection objects that support sort functionality so that I dont have to write my own sorting algorithm?
- Index(es):
Relevant Pages
|