C# | Get the minimum value in the SortedSet
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:
// C# code to get the minimum value // in the SortedSet using System; using System.Collections.Generic; class GFG { // Driver code public static void Main() { // Creating a SortedSet of integers SortedSet< int > mySet = new SortedSet< int >(); // Inserting elements into SortedSet for ( int i = 0; i < 10; i++) { mySet.Add(i); } // Displaying the minimum value in the SortedSet Console.WriteLine( "The minimum element in SortedSet is : " + mySet.Min); } } |
The minimum element in SortedSet is : 0
Example 2:
// C# code to get the minimum value // in the SortedSet using System; using System.Collections.Generic; class GFG { // Driver code public static void Main() { // Creating a SortedSet of strings SortedSet< string > mySet = new SortedSet< string >(); // Inserting elements into SortedSet mySet.Add( "A" ); mySet.Add( "B" ); mySet.Add( "C" ); mySet.Add( "D" ); mySet.Add( "E" ); mySet.Add( "F" ); // Displaying the minimum value in the SortedSet Console.WriteLine( "The minimum element in SortedSet is : " + mySet.Min); } } |
The minimum element in SortedSet is : A
Reference:
Recommended Posts:
- C# | How to create a SortedSet
- SortedSet in C# with Examples
- C# | Get the maximum value in the SortedSet
- C# | Add element to SortedSet
- C# | SortedSet Class
- C# | How to get a subset in a SortedSet
- C# | Get an enumerator that iterates through the SortedSet
- C# | Remove a specified item from SortedSet
- C# | Get the number of elements in the SortedSet
- C# | Remove all elements from the SortedSet
- C# | Intersection of SortedSet with a collection
- C# | Union of SortedSet to a collection
- C# | Check if the SortedSet contains a specific element
- C# | Check if two SortedSet<T> objects are equal
- C# | Check if SortedSet and the specified collection contain the same elements
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.