C# | Get the number of elements contained in SortedList Last Updated : 01 Feb, 2019 Comments Improve Suggest changes Like Article Like Report 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# Program to count the number // of elements in SortedList using System; using System.Collections; class Geeks { // Main Method public static void Main(String[] args) { // Creating object of SortedList // fslist is the SortedList object SortedList fslist = new SortedList(); // Count property is used to get the // number of key/value pairs in fslist // It will give 0 as no pairs are present Console.WriteLine(fslist.Count); } } Output: 0 Example 2: CSharp // C# Program to count the number // of elements in SortedList using System; using System.Collections; class Geeks { // Main Method public static void Main(String[] args) { // Creating object of SortedList // fslist is the SortedList object SortedList fslist = new SortedList(); // Count property is used to get the // number of key/value pairs in fslist // It will give 0 as no pairs are present Console.WriteLine(fslist.Count); // Adding key/value pairs in fslist fslist.Add("1", "GFG"); fslist.Add("2", "Geeks"); fslist.Add("3", "for"); fslist.Add("4", "Geeks"); // Count property is used to get the // number of key/value pairs in fslist // It will give output 4 Console.WriteLine(fslist.Count); } } Output: 0 4 Note: Key/value pair can be accessed as a DictionaryEntry object. The count is the number of elements which are actually present in the SortedList but capacity is the number of elements which can be stored by the SortedList object. Capacity is always greater than or equal to Count. If Count exceeds Capacity while adding elements, the capacity is automatically increased by reallocating the internal array before copying the old elements and adding the new elements. Retrieving the value of this property is an O(1) operation. Reference: https://docs.microsoft.com/en-us/dotnet/api/system.collections.sortedlist.count?view=netframework-4.7.2 Comment More infoAdvertise with us Next Article C# | Get the number of elements contained in SortedList K Kirti_Mangal Follow Improve Article Tags : C# CSharp-Collections-Namespace CSharp-Collections-SortedList Similar Reads 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 number of elements in the SortedSet 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 elemen 2 min read C# | Get the number of elements contained in Collection<T> Collection<T>.Count property is used to get the number of elements actually contained in the Collection<T>. Syntax: public int Count { get; } Return Value: The number of elements actually contained in the Collection<T>. Below given are some examples to understand the implementation 2 min read C# | Get the number of elements actually contained in the ArrayList ArrayList represents an ordered collection of an object that can be indexed individually. It is basically an alternative to an array. It also allows dynamic memory allocation, adding, searching and sorting items in the list. ArrayList.Count property gets the number of elements actually contained in 3 min read Like