Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Sorting a collection in alphabetical order

Tags:

c#

sorting

Is there any way, out of the box, to sort a collection in alphabetical order (using C# 2.0 ?).

Thanks

like image 462
Amokrane Chentir Avatar asked Nov 30 '22 18:11

Amokrane Chentir


1 Answers

What sort of collections are we talking about? A List<T>? ICollection<T>? Array? What is the type stored in the collection?

Assuming a List<string>, you can do this:

 List<string> str = new List<string>();
 // add strings to str

 str.Sort(StringComparer.CurrentCulture);
like image 112
thecoop Avatar answered Dec 17 '22 00:12

thecoop