List<T>::Contains Method (T)
Determines whether an element is in the List<T>.
Assembly: mscorlib (in mscorlib.dll)
Parameters
Implements
ICollection<T>::Contains(T)This method determines equality by using the default equality comparer, as defined by the object's implementation of the IEquatable<T>::Equals method for T (the type of values in the list).
This method performs a linear search; therefore, this method is an O(n) operation, where n is Count.
The following example contains a list of complex objects of type Cube. The Cube class implements the IEquatable<T>::Equals method so that two cubes are considered equal if their dimensions are the same. In this example, the Contains method returns true, because a cube that has the specified dimensions is already in the collection.
Available since 8
.NET Framework
Available since 2.0
Portable Class Library
Supported in: portable .NET platforms
Silverlight
Available since 2.0
Windows Phone Silverlight
Available since 7.0
Windows Phone
Available since 8.1