An array stores a fixed-size sequential collection of elements of the same type. We can use them to gather items in a single group, and perform various operations on them.

Arrays are of the following three types in C#.

  1. One Dimensional Array

    Syntax:

    DataType[] NameOfArray = new DataType[Number of Elements(Size)];

    For Example:
    1. Int[] Arr = new int[5];
    In the above example we have created one dimension array of Type int and having size 5.

  2. Two Dimensional Array

    Syntax:

    DataType[,] NameOfArray = new DataType[Sze of Rows, Size of Column];

    For Example:
    1. Int[,] Arr = new int[5,5];
    In the above example we have created one dimension array of Type Integer.

    Two Dimensional means the array will look like a table with fixed numbers of rows and columns declared in syntax.

  3. Jagged Array

    Syntax:

    DataType[][] NameOfArray = new DataType[Number of Elements(Size)][];

    For Example:
    1. Int[][] Arr = new int[5][];
    Jagged Arrays are basically collection of arrays. In the case of jagged array every Element of an array contains array.

Advantages

There are some advantages of using Arrays.

Drawback

This is the basic concept of creating arrays in C#. You will get the process to insert/select the element using loops and index in an array in my next blog.