Defining Array in C#-
int[] runs = new int[10];
Now let us initialize the array in the same line-
int[] runs = new int[5] {99, 92, 95};
The following example shows how to declare, initialize and display array-
using System; namespace Program { class Demo { static void Main(string[] args) { int[] runs = new int[3] {149, 123, 257}; int j; for (j = 0; j < 3; j++ ) { Console.WriteLine("Score of Cricketer[{0}] = {1}", j, runs[j]); } Console.ReadKey(); } } }
The above is the detailed content of How to define array in C#?. For more information, please follow other related articles on the PHP Chinese website!