int a=124;
int b=123;
int c=12;
int d=1265;
Or that
int [] array = {124,123,12,1265};
Arrays in C # differ in a few respects from tables in C or C ++, for example:
int [] array;
The above code creates an empty array of int, it can not be done because we have not yet allocated this table in memory and we did not put any data there, we must first determine how big this array, we determined that there will be 6 values.
array = new int[6];
and we save these values to it
array[0]=12;
array[1]=15;
array[2]=20;
array[3]=43;
array[4]=35;
array[5]=98;
Cells are always numbered from zero, you can shorten the above record as I showed at the beginning, that is:
int [] array = {12,15,,20,43,35,98};
And below is a program that should explain everything:
static void Main(string[] args)
{
Console.WriteLine("Enter the size of the array");
int a = int.Parse(Console.ReadLine());
int[] array = new int[a];
int b = 0;
for (int i=0;i<a;i++)
{
b += 5;
array[i] =b;
Console.WriteLine("The value of the array number "+i+" that "+array[i]);
}
Console.WriteLine("End of the loop");
Console.ReadKey();
}
The multidimensionals arrays differs only from ordinary arrays only in that they can have more rows, one-dimensional arrays always have one, I will explain it briefly with an example program:
static void Main(string[] args)
{
Console.WriteLine("Enter the number of rows in the array");
int rows = int.Parse(Console.ReadLine());
Console.WriteLine("Enter the number of columns in the array");
int columns = int.Parse(Console.ReadLine());
int[,] array= new int[rows,columns];
for (int i=0; i < rows; i++)
{
for (int j = 0; j < columns; j++)
{
Console.WriteLine("Enter the value of the row number " + i + " and column number " + j);
array[i, j] = int.Parse(Console.ReadLine());
Console.WriteLine("Row number " + i + " an array with name 'array' and column number " + j+" are have a common value "+array[i,j]);
}
}
Console.WriteLine("End of the loop");
Console.ReadKey();
}
Rather, you should not have problems understanding this code, first enter the number of rows and columns, then make the first loop, the second loop will be done until you enter all the values in these columns, when you enter all values in columns, we move to the next row.
This content also you can find on my blog devman.pl: http://devman.pl/csharplan/language-c-5-arrays/
If you recognise it as useful, share it with others so that others can also use it and leave upvote and follow if you wait for next articles :) .
If anything is not understood, write in the comments.