How to search an item in a C# List

C# List<T> class provides methods and properties to create a list of objects (classes). You can add items to a list during the initialization or using List.Add() and List.AddRange() methods.
List is a generic class. You must import the following namespace before using the List<T> class. 
  1. using System.Collections.Generic;  
Search an Item in a List
The BinarySearch method uses the binary search algorithm to find an item in the sorted List. 
The following code snippet finds an item in a List. 
  1. // Create a list of strings  
  2. List<string> AuthorList = new List<string>();  
  3. AuthorList.Add("Mahesh Chand");  
  4. AuthorList.Add("Praveen Kumar");  
  5. AuthorList.Add("Raj Kumar");  
  6. AuthorList.Add("Nipun Tomar");  
  7. AuthorList.Add("Dinesh Beniwal");  

  8. AuthorList.Sort();
  9. int itemPosition = AuthorList.BinarySearch("Raj Kumar");  
  10. Console.WriteLine("Item found at position: {0}", itemPosition + 1);