473,320 Members | 1,810 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

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 9669
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Robert Oschler | last post by:
What is the Python equivalent of the C# StringCollection container? I'm trying to port some C# code over to Python. Thanks. Robert
3
by: Jonathan | last post by:
I tried using Type::GetType on S"System.Collections.Specialized.StringCollection", but it returned NULL. The only way it worked was when I used the fully qualified name, including the assembly...
2
by: Dennis Myrén | last post by:
Hi. I want to know why it is not possible to specify (or determine) the capacity for a System.Collections.Specialized.StringCollection. I guess the StringCollection would be the better choice...
2
by: Dan | last post by:
Hi, Is it possible to iterate through a StringCollection ? I have the following code but "row" always seems to contain the values of rowValues2 Thanks for any input, Danny
1
by: Juan Francisco Figueroa Perez | last post by:
Hi all: I have a StringCollection property like this: public class FormExito : Form { ................ ................ private StringCollection FEditar;
8
by: Naz | last post by:
Hi, I am new in C# and converting a program from delphi to C#. I have to store a list of strings in memory and also need to save the strings to disk at the end. I use StringCollection and my...
0
by: Dinesh Rathi | last post by:
Hi I have a managed dll which I am using in my unmanaged application through its com interfaces. Now can I use StringCollection/ String class through com interfaces ? One of my class has a member...
2
by: eSapient | last post by:
I have a case where a C# dll is being consumed by an unmanaged C++ executable. One of the dll methods returns a StringCollection object. What are the requirements for the C++ executable in terms of...
2
by: =?Utf-8?B?YmlsbCB0aWU=?= | last post by:
Why should I use StringCollection as opposed to List<string>? Thank you.
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.