C# | Check if a SortedList object contains a specific value Last Updated : 06 Sep, 2021 Comments Improve Suggest changes Like Article Like Report SortedList class is a collection of (key, value) pairs which are sorted according to keys. Those pairs can be accessible by key and as well as by index(zero-based indexing). This comes under System.Collections namespace. SortedList.ContainsValue(Object) method is used to check whether a SortedList object contains a specific value or not. Properties: A SortedList element can be accessed by its key or by its index.A SortedList object internally maintains two arrays to store the elements of the list, i.e, one array for the keys and another array for the associated values.A key cannot be null, but a value can be.The capacity of a SortedList object is the number of elements the SortedList can hold.A SortedList does not allow duplicate keys.Operations on a SortedList object tend to be slower than operations on a Hashtable object because of the sorting.Elements in this collection can be accessed using an integer index. Indexes in this collection are zero-based. Syntax : public virtual bool ContainsValue (object value); Here, value is the value to locate in the SortedList object and it can be null.Return Value: This method returns True if the SortedList object contains an element with the specified value, otherwise it returns False.Below programs illustrate the use of SortedList.ContainsValue(Object) Method:Example 1: CSHARP // C# code to check if a SortedList // object contains a specific value using System; using System.Collections; class GFG { // Driver code public static void Main() { // Creating an SortedList SortedList mySortedList = new SortedList(); // Adding elements to SortedList mySortedList.Add("1", "1st"); mySortedList.Add("2", "2nd"); mySortedList.Add("3", "3rd"); mySortedList.Add("4", "4th"); // Checking if a SortedList object // contains a specific value Console.WriteLine(mySortedList.ContainsValue(null)); } } Output: False Example 2: CSHARP // C# code to check if a SortedList // object contains a specific value using System; using System.Collections; class GFG { // Driver code public static void Main() { // Creating an SortedList SortedList mySortedList = new SortedList(); // Adding elements to SortedList mySortedList.Add("h", "Hello"); mySortedList.Add("g", "Geeks"); mySortedList.Add("f", "For"); mySortedList.Add("n", "Noida"); // Checking if a SortedList object // contains a specific value Console.WriteLine(mySortedList.ContainsValue("Geeks")); } } Output: True Note: The values of the elements of the SortedList object are compared to the specified value using the Equals method.This method performs a linear search, therefore, the average execution time is proportional to Count, i.e, this method is an O(n) operation, where n is Count. Reference: https://docs.microsoft.com/en-us/dotnet/api/system.collections.sortedlist.containsvalue?view=netframework-4.7.2 Comment More infoAdvertise with us Next Article C# | Check if a SortedList object contains a specific value S Sahil_Bansall Follow Improve Article Tags : C# CSharp-method CSharp-Collections-Namespace CSharp-Collections-SortedList Similar Reads C# | Check whether a SortedList object contains a specific key SortedList.Contains(Object) Method is used to check whether a SortedList object contains a specific key. Syntax: public virtual bool Contains (object key); Here, key is the Key which is to be located in the SortedList object. Return Value: This method returns the true if the SortedList object contai 2 min read C# | Check if the SortedSet contains a specific element SortedSet class represents the collection of objects in sorted order. This class comes under the System.Collections.Generic namespace. SortedSet<T>.Contains(T) Method is used to check if a SortedSet contains a specific element or not. Properties: In C#, SortedSet class can be used to store, remov 2 min read C# | Getting the Values in a SortedList object SortedList.Values Property is used to get the values in a SortedList object. Syntax: public virtual System.Collections.ICollection Values { get; } Property Value: An ICollection object containing the values in the SortedList object. Below programs illustrate the use of above-discussed property: Exam 2 min read C# | Getting the value at the specified index of a SortedList object SortedList.GetByIndex(Int32) Method is used to get the value at the specified index of a SortedList object. Syntax: public virtual object GetByIndex (int index); Here index is the zero-based index of the value to get. Return Value: It returns the value at the specified index of the SortedList object 2 min read C# | Check if the Hashtable contains a specific Value The Hashtable class represents a collection of key-and-value pairs that are organized based on the hash code of the key. The key is used to access the items in the collection. Hashtable.ContainsValue(Object) Method is used to check whether the Hashtable contains a specific value or not. Syntax: publ 2 min read C# | Getting index of the specified value in a SortedList object SortedList.IndexOfValue(Object) Method is used to get the zero-based index of the first occurrence of the specified value in a SortedList object. Syntax: public virtual int IndexOfValue (object value); Here, value is the Value which is to be located in the SortedList object. The value can be null. R 3 min read C# | Check if ListDictionary contains a specific key ListDictionary.Contains(Object) method is used to check whether the ListDictionary contains a specific key or not. Syntax: public bool Contains (object key); Here, key is the key to locate in the ListDictionary. Return Value: The method returns true if the ListDictionary contains an entry with the s 2 min read C# | Check if a SortedSet object is a proper subset of the specified collection SortedSet class represents the collection of objects in sorted order. This class comes under the System.Collections.Generic namespace. SortedSet<T>.IsProperSubsetOf(IEnumerable<T>) method is used to check if a SortedSet<T> object is a proper subset of the specified collection or no 2 min read C# | Check if a SortedSet is a subset of the specified collection SortedSet class represents the collection of objects in sorted order. This class comes under the System.Collections.Generic namespace. SortedSet<T>.IsSubsetOf(IEnumerable<T>) Method is used to check whether a SortedSet<T> object is a subset of the specified collection or not. Properties: In 2 min read C# | Check if a SortedList object is synchronized SortedList class is a collection of (key, value) pairs which are sorted according to keys. Those pairs can be accessible by key and as well as by index(zero-based indexing). This comes under System.Collections namespace. SortedList.IsSynchronized property is used to get a value indicating whether ac 2 min read Like