C# | Get the minimum value in the SortedSet
Last Updated :
01 Feb, 2019
SortedSet class represents the collection of objects in sorted order. This class comes under the System.Collections.Generic namespace. SortedSet<T>.Min Property is used to get minimum value in the SortedSet<T>, as defined by the comparer.
Properties:
- In C#, SortedSet class can be used to store, remove or view elements.
- It maintains ascending order and does not store duplicate elements.
- It is suggested to use SortedSet class if you have to store unique elements and maintain ascending order.
Syntax:
mySet.Min
Here, mySet is the object of the SortedSet.
Return Value: Minimum value in the SortedSet.
Below programs illustrate the use of SortedSet<T>.Min Property:
Example 1:
using System;
using System.Collections.Generic;
class GFG {
public static void Main()
{
SortedSet< int > mySet = new SortedSet< int >();
for ( int i = 0; i < 10; i++) {
mySet.Add(i);
}
Console.WriteLine( "The minimum element in SortedSet is : " + mySet.Min);
}
}
|
Output:
The minimum element in SortedSet is : 0
Example 2:
using System;
using System.Collections.Generic;
class GFG {
public static void Main()
{
SortedSet< string > mySet = new SortedSet< string >();
mySet.Add( "A" );
mySet.Add( "B" );
mySet.Add( "C" );
mySet.Add( "D" );
mySet.Add( "E" );
mySet.Add( "F" );
Console.WriteLine( "The minimum element in SortedSet is : " + mySet.Min);
}
}
|
Output:
The minimum element in SortedSet is : A
Reference:
Like Article
Suggest improvement
Share your thoughts in the comments
Please Login to comment...