Use the BinarySearch() method to search stringArray for 'abc345' : Array Search : Data Structure C# Examples


C# Examples » Data Structure » Array Search »

 

Use the BinarySearch() method to search stringArray for 'abc345'









    
using  System;

class  MainClass
{

    public  static  void  Main()
    {
        string[]  stringArray  =  {"t",  "i",  "a",  "test",  "abc123",  "abc345"};
        Array.Sort(stringArray);
                
        int  index  =  Array.BinarySearch(stringArray,  "abc345");
        Console.WriteLine("Array.BinarySearch(stringArray,  \"abc345\")  =  "  +  index);

    }

}
    
   
  
   



Output

Array.BinarySearch(stringArray, "abc345") = 2


HTML code for linking to this page:

Follow Navioo On Twitter

C# Examples

 Navioo Data Structure
» Array Search