Sort an array and search for a value : Array Sort : Data Structure C# Examples


C# Examples » Data Structure » Array Sort »

 

Sort an array and search for a value









    
using  System;    
    
class  MainClass  {          
    public  static  void  Main()  {          
        int[]  nums  =  {  5,  4,  6,  3,  14,  9,  8,  17,  1,  24,  -1,  0  };  
      
        Array.Sort(nums);  
  
          //  Search  for  14.  
        int  idx  =  Array.BinarySearch(nums,  14);  
  
        Console.WriteLine("Index  of  14  is  "  +  idx);  
    }          
}
    
   
  
   



Output

Index of 14 is 9


HTML code for linking to this page:

Follow Navioo On Twitter

C# Examples

 Navioo Data Structure
» Array Sort