Array :

  • An Array is a set of similar types values ,that are stored in sequential order ,it is an user defined data type used to store more than one value with the same name and all value is identified using the index. In C# an array index starts at zero (0) means that all items will be start or count at the zero position and last position will be (total number -1).In C# array are reference type.

  • Types of array:

  • In C# 3 types of array is..
  • Single dimensional Array:

  • An Array which contains single row or single column are called as single dimensional array.

  • 20 10 30 40 25 35

    Syntax :

  • int [ ] arr =new [size];
  • EXP:


  • int [ ] arr =new int [6]/{ list of value};

  • Program of single dimensional array:



    using System;
    usingSystem.Collection.Generic;
    usingSystem.Linq;
    usingSystem.Text; 
    
      Namespace BASIC {
    		classArraySingle {
    			static void Main() {
    				Int [ ] A=new int [] {20,10,30,40,25,35};
    				Console.WriteLine(“Numbers of Array are…”);
                    
    				for ( int i=0 ; I <6; i++) 
                     	{
    					   Console.Write(A[i]+ “ “);
    					}
                        
    				Console.Read();
    			}
    		}
    	}
    


    2. Multi dimensional Array:

  • these array are stored data in form of rows and columns are calles as Multi dimensional Array.

  • 20 30 50 40 10

    20
    30
    50
    40
    10

    Syntax OfMulti dimensional Array:

  • [ ,] =new [rows,column];
  • Exp :Int[ ,] arr =new int [5,6];

  • Programe of Multi dimensional Array:

    
    using  System;
    class multidArrayDemo {
    	int[ ,]arr =new int [5,6];
    	int a=0;
    	for (int i =0; i<arr.GetLength(0); i++) {
    		for (int j=0; j<arr.GetLength(1); j++) {
    			arr[i,j]=a;
    			a+=5;
    		}
    	}
    	for (int i=0;i<GetLength(0);i++) {
    		for (int j=0;j.GetLength(1); j++) {
    			Console.WriteLine(arr[i,j]+ “ “);
    			Console.WriteLine();
    		}
    	}
    	Console.ReadLine();
    }
    }
    

    3. Jagged Array :


  • Jagged array is a collection of rows which may contain distinct number of element in each row .it is collection of single Dimensional Array. This is used for save the memory.
  • 20
    10
    40
    50

           

  • It means row is working like single dimensional array but column is empty because it works like single dimensional array.

  • Syntax :

  • [ ][ ] =new [size(no of Rows)] [ ];


  • Programme of jagged array:

    using System ;
    Class JaggedDemo {
    	static void Main() {
    		int [][] a=new int [5][];
    		a[0]=new int [] {
    			10,20,30
    		}
    		;
    		a[1]=new int [] {
    			10,20,30,40
    		}
    		;
    		a[2]=new int [] {
    			10,20,30,40,50
    		}
    		;
    		a[3]=new int [] {
    			10,20,30,40,50,60
    		}
    		;
    		a[4]=new int [] {
    			10,20,30,40,50,60,70
    		}
    		;
    		for (int i=0; i<a.GetLength;  i++) {
    			Console.WriteLine(a[i][j]+ “ “);
    		}
    		Console.WriteLine();
    	}
    	Console.ReadLine();
    }
    }