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

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



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: Efficient python 2-d arrays?
    ... I can create large 2-dimensional arrays quite easily. ... my target audience may not have numpy so I'd prefer not to use it. ... Since I want to keep the two elements together during a sort, ... Use a list of lists, where the outer list is the easier one to sort ...
    (comp.lang.python)
  • Re: A Sorting Puzzle
    ... Rows and columns of tables, although indexable, are not arrays, and have ... Since the elements can be both read and written, all normal sort ... generate directly comparable sort keys. ... That's easy in JavaScript. ...
    (comp.lang.javascript)
  • 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)