Mid Collections

What methods does the List<T> class provide to search for an element?

  • Contains(item)
  • IndexOf(item)
  • Find(predicate)
  • FindAll(predicate)
  • Exists(predicate)
  • BinarySearch(item) (for sorted lists)

Example:

bool hasItem = numbers.Contains(10);

int index = numbers.IndexOf(10);

var result = numbers.Find(x => x > 50);

More from C# Programming Tutorial

All questions for this course