468,321 Members | 1,836 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,321 developers. It's quick & easy.

Sorting StringCollection?

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

Nov 17 '05 #1
3 9034
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
"Ben Fidge" wrote:
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

Nov 17 '05 #2
Salvador <Sa******@discussions.microsoft.com> wrote:
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 - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 17 '05 #3
"Jon Skeet [C# MVP]" wrote:
Salvador <Sa******@discussions.microsoft.com> wrote:
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.


and if you insist on StringCollection, what you can do is use
ArrayList.Adapter to create a wrapper for sorting the string collection.
--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too

Nov 17 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by Robert Oschler | last post: by
3 posts views Thread by Jonathan | last post: by
2 posts views Thread by Dennis Myrén | last post: by
2 posts views Thread by Dan | last post: by
1 post views Thread by Juan Francisco Figueroa Perez | last post: by
8 posts views Thread by Naz | last post: by
reply views Thread by Dinesh Rathi | last post: by
2 posts views Thread by =?Utf-8?B?YmlsbCB0aWU=?= | last post: by
reply views Thread by NPC403 | last post: by
1 post views Thread by howard w | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.