C# | Get the number of elements in the SortedSet Last Updated : 01 Feb, 2019 Comments Improve Suggest changes Like Article Like Report SortedSet class represents the collection of objects in sorted order. This class comes under the System.Collections.Generic namespace. SortedSet<T>.Count Property is used to get the number of elements in the SortedSet. 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: mySortedSet.Count Here, mySortedSet is a SortedSet. Below given are some examples to understand the implementation in a better way: Example 1: CSHARP // C# code to get the number of // elements in the SortedSet using System; using System.Collections.Generic; class GFG { // Driver code public static void Main() { // Creating a SortedSet of integers SortedSet<int> mySortedSet = new SortedSet<int>(); // adding elements in mySortedSet mySortedSet.Add(1); mySortedSet.Add(2); mySortedSet.Add(3); mySortedSet.Add(4); mySortedSet.Add(5); // Displaying the number of elements in // the SortedSet using "Count" function Console.WriteLine("The number of elements in mySortedSet are: " + mySortedSet.Count); } } Output: The number of elements in mySortedSet are: 5 Example 2: CSHARP // C# code to get the number of // elements in the SortedSet using System; using System.Collections.Generic; class GFG { // Driver code public static void Main() { // Creating a SortedSet of strings SortedSet<string> mySortedSet = new SortedSet<string>(); // adding elements in mySortedSet mySortedSet.Add("Hey"); mySortedSet.Add("GeeksforGeeks"); mySortedSet.Add("and"); mySortedSet.Add("Geeks Classes"); // Displaying the number of elements in // the SortedSet using "Count" function Console.WriteLine("The number of elements in mySortedSet are: " + mySortedSet.Count); } } Output: The number of elements in mySortedSet are: 4 Reference: https://docs.microsoft.com/en-us/dotnet/api/system.collections.generic.sortedset-1.count?view=netcore-2.1 Comment More infoAdvertise with us Next Article C# | Get the number of elements in the SortedSet S Sahil_Bansall Follow Improve Article Tags : Misc C# CSharp-Generic-SortedSet CSharp-Generic-Namespace Practice Tags : Misc Similar Reads C# | Get the number of elements contained in SortedList SortedList.Count Property is used to get the number of elements contained in a SortedList object. Syntax: public virtual int Count { get; } Property Value: The number of elements contained in the SortedList object. Below programs illustrate the use of above discussed method: Example 1: CSharp // C# 2 min read C# | Get the number of elements contained in the Stack Stack represents a last-in, first out collection of object. Stack<T>.Count Property is used to gets the number of elements contained in the Stack. Retrieving the value of this property is an O(1) operation. Syntax: myStack.Count Here myStack is the name of the Stack<T> Return Value: The 2 min read C# | Get the number of elements contained in the Queue Queue represents a first-in, first out collection of object. It is used when you need a first-in, first-out access of items. When you add an item in the list, it is called enqueue, and when you remove an item, it is called deque. Queue.Count Property is used to get the number of elements contained i 2 min read 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 2 min read C# | Total number of elements present in an array Array.GetLength(Int32) Method is used to find the total number of elements present in the specified dimension of the Array. Syntax: public int GetLength (int dimension); Here, dimension is a zero-based dimension of the Array whose length needs to be determined.Return value: The return type of this m 2 min read Like