Mid Collections

How does the Contains() method work in a List<T>?

Contains(item) checks whether the item exists in the list. It uses Equals() internally.

Example:

Follow:

bool exists = list.Contains(10);

Note: For custom objects, override Equals() and GetHashCode().

More from C# Programming Tutorial

All questions for this course