Sorting StringCollection?

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi

What are the options for sorting a StringCollection? I'm quite surprised
that StringCollection doesn't have any sorting capability built in!

Thanks
Ben
 
Hi,

The reason is that a string collection is an specialized collections that
does not require boxing, that is a huge benefit from a normal collection.
(this is solved with generics on .NET 2005).

If you need sorting capabilities use a SortList, that is intended for it.
Otherwise you have plenty of sorting algorithms on the net, bubble, hash,
binary, etc.

Cheers
Salva
 
Salvador said:
The reason is that a string collection is an specialized collections that
does not require boxing, that is a huge benefit from a normal collection.

Not for strings it wouldn't - no boxing would be required as string is
a reference type.

StringCollection is basically just strongly typed.
(this is solved with generics on .NET 2005).

If you need sorting capabilities use a SortList, that is intended for it.

Not really - SortedList is badly named, as it's effectively a
dictionary sorted by key.

ArrayList can be sorted, however - that would be a better choice.
 
Jon Skeet said:
Not for strings it wouldn't - no boxing would be required as string is
a reference type.

StringCollection is basically just strongly typed.


Not really - SortedList is badly named, as it's effectively a
dictionary sorted by key.

ArrayList can be sorted, however - that would be a better choice.

and if you insist on StringCollection, what you can do is use
ArrayList.Adapter to create a wrapper for sorting the string collection.
 
Back
Top