標籤:
可以在一個數組資料結構中儲存同一類型的多個變數。 通過指定其元素的型別宣告數組
type []arrayName;
1 class TestArraysClass 2 { 3 static void Main() 4 { 5 // Declare a single-dimensional array 一維數組 6 int[] array1 = new int[5]; 7 8 // Declare and set array element values 9 int[] array2 = new int[] { 1, 3, 5, 7, 9 };10 11 // Alternative syntax12 int[] array3 = { 1, 2, 3, 4, 5, 6 };13 14 // Declare a two dimensional array 多維陣列15 int[,] multiDimensionalArray1 = new int[2, 3];16 17 // Declare and set array element values18 int[,] multiDimensionalArray2 = { { 1, 2, 3 }, { 4, 5, 6 } };19 20 // Declare a jagged array 交錯數組21 int[][] jaggedArray = new int[6][];22 23 // Set the values of the first array in the jagged array structure24 jaggedArray[0] = new int[4] { 1, 2, 3, 4 };25 }26 }
數組的屬性:
當建立了數組執行個體時,將建立維度數和每個維度長度。 在執行個體的生存期內,這些值不能更改。
數值數組元素的預設值設定為零,而引用元素的預設值設定為 null。
交錯數組是數組的數組,因此其元素是參考型別並初始化為 null。
數組的索引從零開始:具有 n 個元素的數組的索引是從 0 到 n-1。
數組元素可以是任何類型,包括數群組類型
數組簡述(C# 編程指南)