List<T>.Contains(T) Method is used to check whether an element is in the List<T> or not.
Properties of List:
- It is different from the arrays. A list can be resized dynamically but arrays cannot.
- List class can accept null as a valid value for reference types and it also allows duplicate elements.
- If the Count becomes equals to Capacity then the capacity of the List increases automatically by reallocating the internal array. The existing elements will be copied to the new array before the addition of the new element.
public bool Contains (T item);
Here, item is the object which is to be locate in the List<T>. The value can be null for reference types.
Return Value: This method returns True if the item is found in the List<T> otherwise returns False.
Below programs illustrate the use of List<T>.Contains(T) Method:
- C# | Check if every List element matches the predicate conditions
- C# | Adding an element to the List
- C# | Removing the specified element from the List
- C# | How to remove the element from the specified index of the List
- C# | How to perform a specified action on each element of the List
- C# | Gets or Sets the element at the specified index in the List
- C# | How to get the last occurrence of the element in the List that match the specified conditions
- C# | Check if a HashSet contains the specified element
- C# | Check if a Stack contains an element
- C# | Check if an element is in the Queue
- C# | Check if an element is in the Collection<T>
- C# | Check if the SortedSet contains a specific element
- C# | Check whether an element is contained in the ArrayList
- C# | Check if two List objects are equal
- C# | How to check whether a List contains the elements that match the specified conditions
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.