Array Declaration in C#

One Dimensional Arrays:
Array declaration in C# is different from c or c++.In C# arrays are declared with new reserve word.
   int[] numbers = new int[10];
This will declare an array of size 10 with name numbers.
Another method to declare one dimensional array is
int[] numbers = { 1, 2, 3, 4, 5, 6 };
Two Dimensional Arrays:
int[,] numbers = new int[2, 2];
This will declare a two dimensional array of 2*2.Unlike c++ two dimensional array in C# is separated with , Now we input values in this array using for loop.
for (int i=0;i< 2;i++)
                for(int j=0;j<2;j++)
            {
                Console.Write("Enter value for {0},{1} location ", i, j);
                numbers[i, j] = int.Parse(Console.ReadLine());
            }

Comments

Post a Comment

Popular posts from this blog

Using Progress Bar In C#

Get elements by class name in javascript

Jquery serer side datatables in asp.net