.NET Framework 4.0 Newbie : SortedSet<T>

.NET Framework 4.0 Newbie : SortedSet<T>

  • Comments 0

In .NET Framework 4.0 we have a new class called SortedSet<T>. This helps us to sort the elements without explicitly we implementing any sort method.

var sSet = new SortedSet<int> { 2, 4, 6, 8, 9, 1, 3, 5, 7 };

 

//Getting directly the sorted output

foreach (int iVal in sSet)

{

    Console.WriteLine(iVal);

}

 

This would give you output in the following order,

 

1

2

3

4

5

6

7

8

9

 

Also we can get Min and Max

//Min & Max

Console.WriteLine("Max = {0}", sSet.Max);

Console.WriteLine("Min = {0}", sSet.Min);

 

This could be helpful wherever we predict to call a Sort function while working with the collection.

Namoskar!!!

Leave a Comment
  • Please add 5 and 1 and type the answer here:
  • Post