Collection<T>.Contains(T) method is used to determine whether an element is in the Collection<T>.
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 is found in the Collection<T>, otherwise, False.
Below given are some examples to understand the implementation in a better way:
Note: This method performs a linear search. Therefore, this method is an O(n) operation, where n is Count.
- C# | Check whether an element is contained in the ArrayList
- C# | Check if a Stack contains an element
- C# | Check if an element is in the Queue
- C# | Check if a HashSet contains the specified element
- C# | Check if the SortedSet contains a specific element
- C# | How to check whether a List contains a specified element
- C# | Check if every List element matches the predicate conditions
- C# | Insert an element into the ArrayList at the specified index
- C# | Adding an element into the Hashtable
- C# | Add element to HashSet
- C# | Remove the element with the specified key from the Hashtable
- C# | Add element to SortedSet
- C# | Adding an element to the List
- C# | Removing the specified element from the List
- C# | Remove the specified element from a HashSet
- C# | Gets or Sets the element at the specified index in the List
- C# | Remove the element at the specified index of the ArrayList
- C# | How to remove the element from the specified index of the List
- C# | How to get the last occurrence of the element in the List that match the specified conditions
- C# | How to perform a specified action on each element of the List
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. 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.