在C#中創建數組并添加數據有以下幾種方法:
int[] numbers = {1, 2, 3, 4, 5};
int[] numbers = new int[5];
numbers[0] = 1;
numbers[1] = 2;
numbers[2] = 3;
numbers[3] = 4;
numbers[4] = 5;
int[] numbers = new int[5];
for (int i = 0; i < numbers.Length; i++)
{
numbers[i] = i + 1;
}
無論采用哪種方法,都可以為數組添加數據。