Use the IndexOf() and LastIndexOf() methods to find the value 1 in intArray : Array Index : Data Structure C# Examples


C# Examples » Data Structure » Array Index »

 

Use the IndexOf() and LastIndexOf() methods to find the value 1 in intArray









    
using  System;

class  MainClass
{

    public  static  void  Main()
    {
        int[]  intArray  =  {1,  2,  1,  3};
        Console.WriteLine("intArray:");
        for  (int  i  =  0;  i  <  intArray.Length;  i++)
        {
            Console.WriteLine("intArray["  +  i  +  "]  =  "  +
                intArray[i]);
        }

        
        int  index  =  Array.IndexOf(intArray,  1);
        Console.WriteLine("Array.IndexOf(intArray,  1)  =  "  +  index);
        index  =  Array.LastIndexOf(intArray,  1);
        Console.WriteLine("Array.LastIndexOf(intArray,  1)  =  "  +  index);
    }

}
    
   
  
   



Output

intArray:
intArray[0] = 1
intArray[1] = 2
intArray[2] = 1
intArray[3] = 3
Array.IndexOf(intArray, 1) = 0
Array.LastIndexOf(intArray, 1) = 2


HTML code for linking to this page:

Follow Navioo On Twitter

C# Examples

 Navioo Data Structure
» Array Index