C# array

An array contains a group of data with specific type, such as integer array, string array, double array etc.

int[] arr;
int[] arr = new int[] {3,4,2,1,5,8};
string[5] arr;

Loop through an array:
string[] cities = new string[] {"Boston","New York","Houston"};
for (int i=0;i < cities.Length,i++)
{
string city = cities[i];
...
}

Multidimentional arrays:
int[,] arr = new int[4,5]; //two dimentional array
int[,] arr = new int[,] {{2,3,4},{11,12,24}};

Array of objects:
class A
{
...
}
A[] arr = new A[5];

You can not add new elements to an existing array. You can use list instead.

endmemo.com © 2024  | Terms of Use | Privacy | Home