Re: does C# have any collection objects that support sort functionality so that I dont have to write my own sorting algorithm?



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


.



Relevant Pages

  • Re: Help with Array(s)
    ... I would think XML would return in something with an XML schema and you could ... Array.Sort sorts one-dimentional arrays, but don't think it will 2dim arrays ... to sort list by second int value and display. ...
    (microsoft.public.dotnet.languages.vb)
  • Re: Arrays
    ... > Arrays are very rich objects in CL. ... > copying some sort of object, or testing one for equality, there are ... > The Lisp reader does a lot of this when reading strings and symbols. ...
    (comp.lang.lisp)
  • Re: IsAnagram
    ... Sort both words and compare both arrays. ... So I am looking for the most efficient algorithm. ... Sort both sounds like the most efficient. ... array first. ...
    (comp.lang.c)
  • Re: Sorting Dataset
    ... You could then sort on this column. ... anything that Implements IList can be used to bind the grid. ... Furthermore ArrayLists for instance have a .Sort ... "Chris Kennedy" wrote in message ...
    (microsoft.public.dotnet.framework.adonet)
  • Re: Generic In-Place Sort
    ... > There is a bug in that you get an Access Violation if you sort an empty ... So with an empty array, ... specializations for sorting arrays of Integers and arrays of strings. ...
    (comp.lang.pascal.delphi.misc)

Loading