posted 6/7/2010 by Samir NIGAM
In .NET Framework 4.0, we can sort a list of elements without explicitly implementing any sort algorithms through a new class SortedSet<T>.Let’s create an instance of SortedSet class as-
SortedSet<string> sortedSet = new SortedSet<string> { "samir", "kumar", "nigam", "tanu", "nitin" };
Let’s print this set through foreach loop as-
foreach (string element in sortedSet) Response.Write(string.Format(" {0}", element));
And we get sorted output as-kumar nigam niti samir tanu You can also Add elements in the set at run time and set will get sorted implicitly. e.g. let’s add an element in the set as-
sortedSet.Add("ram"); foreach (string element in sortedSet) Response.Write(string.Format(" {0}", element));
And we get sorted output as-kumar nigam niti ram samir tanuReally this is very great new feature in .NET 4.0
What kind of email newsletter would you prefer to receive from CodeAsp.Net?18