C# | Check if a value is in LinkedList<T> Last Updated : 22 Jun, 2022 Comments Improve Suggest changes Like Article Like Report LinkedList<T>.Contains(T) method is used to check whether a value is in the LinkedList<T> or not. Syntax: public bool Contains (T value); Here, value is the value to locate in the LinkedList<T>. The value can be null for reference types. Return Value: This method returns True if value is found in the LinkedList, otherwise, False. Below given are some examples to understand the implementation in a better way: Example 1: CSHARP // C# code to check if a // value is in LinkedList using System; using System.Collections; using System.Collections.Generic; class GFG { // Driver code public static void Main() { // Creating a LinkedList of Strings LinkedList<String> myList = new LinkedList<String>(); // Adding nodes in LinkedList myList.AddLast("A"); myList.AddLast("B"); myList.AddLast("C"); myList.AddLast("D"); myList.AddLast("E"); // To check if a value is in LinkedList Console.WriteLine(myList.Contains("B")); } } Output: True Example 2: CSHARP // C# code to check if a // value is in LinkedList using System; using System.Collections; using System.Collections.Generic; class GFG { // Driver code public static void Main() { // Creating a LinkedList of Integers LinkedList<int> myList = new LinkedList<int>(); // Adding nodes in LinkedList myList.AddLast(1); myList.AddLast(2); myList.AddLast(3); myList.AddLast(4); myList.AddLast(5); // To check if a value is in LinkedList Console.WriteLine(myList.Contains(8)); } } Output: False Note: This method performs a linear search. Therefore, this method is an O(n) operation, where n is Count. Space complexity: O(n) where n is size of the LinkedList Reference: https://docs.microsoft.com/en-us/dotnet/api/system.collections.generic.linkedlist-1.contains?view=netframework-4.7.2 Comment More infoAdvertise with us Next Article C# | Check if a value is in LinkedList<T> S Sahil_Bansall Follow Improve Article Tags : C# CSharp-Generic-Namespace CSharp-LinkedList CSharp-LinkedList-Methods Similar Reads C# | Check if two LinkedList<T> objects are equal Equals(Object) Method which is inherited from the Object class is used to check if a specified LinkedList<T> object is equal to another LinkedList<T> object or not. Syntax: public virtual bool Equals (object obj); Here, obj is the object which is to be compared with the current object. R 2 min read C# | Check if an element is in the Collection<T> Collection<T>.Contains(T) method is used to determine whether an element is in the Collection<T>. Syntax: public bool Contains (T item); Here, item is the object to locate in the Collection<T>. The value can be null for reference types. Return Value: This method return True if item 2 min read C# | Check if an element is 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.Contains(T) Method is used to check whether an element is in the 2 min read C# | Check if a SortedList object contains a specific value 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 o 2 min read C# | Getting an enumerator that iterates through LinkedList<T> LinkedList<T>.GetEnumerator Method is used to get an enumerator that iterates through the LinkedList<T>. Syntax: public System.Collections.Generic.LinkedList<T>.Enumerator GetEnumerator (); Return Value: It returns an LinkedList<T>.Enumerator for the LinkedList<T>. Belo 2 min read C# | Get the last node of the LinkedList<T> LinkedList<T>.Last property is used to get the last node of the LinkedList<T>. Syntax: public System.Collections.Generic.LinkedListNode Last { get; } Return Value: The last LinkedListNode<T> of the LinkedList<T>. Below given are some examples to understand the implementation 2 min read C# | Adding new node or value at the end of LinkedList<T> LinkedList<T>.AddLast Method is used to add a new node or value at the end of the LinkedList<T>. There are 2 methods in the overload list of this method as follows: AddLast(LinkedList<T>) AddLast(T) AddLast(LinkedListNode<T>) This method is used to add the specified new node 3 min read C# | Get the number of nodes contained in LinkedList<T> LinkedList<T>.Count property is used to get the number of nodes actually contained in the LinkedList<T>. Syntax: public int Count { get; } Return Value: The number of nodes actually contained in the LinkedList. Note: Retrieving the value of this property is an O(1) operation. Below given 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# | Check if a SortedList is read-only 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.IsReadOnly property is used to get a value which indicates that a So 2 min read Like