Array Declaration with initialization : Array : Data Structure C# Examples


C# Examples » Data Structure » Array »

 

Array Declaration with initialization





The general form for initializing a one-dimensional array is shown here:




    
type[  ]  array-name  =  {  val1,  val2,  val3,  ...,  valN  };
    
   
  
   





    
using  System;  
  
class  MainClass  {    
    public  static  void  Main()  {    
        int[]  nums  =  {  99,  10,  100,  18,  78,  23,  
                                      63,  9,  87,  49  };  
        int  avg  =  0;  
  
        for(int  i=0;  i  <  10;  i++)    
            avg  =  avg  +  nums[i];  
  
        avg  =  avg  /  10;  
  
        Console.WriteLine("Average:  "  +  avg);  
    }    
}
    
   
  
   



Output

Average: 53


HTML code for linking to this page:

Follow Navioo On Twitter

C# Examples

 Navioo Data Structure
» Array