Use the BinarySearch() method to search charArray for 'o' : Array Search « Data Structure « C# / CSharp Tutorial






using System;

class MainClass
{

  public static void Main()
  {
    char[] charArray = {'w', 'e', 'l', 'c', 'o', 'm', 'e'};
    Array.Sort(charArray);  // sort the elements        
    int index = Array.BinarySearch(charArray, 'o');
    Console.WriteLine("Array.BinarySearch(charArray, 'o') = " + index);

  }

}
Array.BinarySearch(charArray, 'o') = 5








11.17.Array Search
11.17.1.Use the BinarySearch() method to search intArray for the number 5
11.17.2.Use the BinarySearch() method to search intArray for the number 4: BinarySearch() returns a negative value
11.17.3.Use the BinarySearch() method to search stringArray for 'abc345'
11.17.4.Use the BinarySearch() method to search charArray for 'o'