1、一維數組(值類型)
- int[] myIntegers; //申明一個數組的引用
- myIntegers = new int[100]; //建立一個含有100個int元素的資料
2、一維數組(引用類型)
- Control[] myControls; //聲明一個數組引用
- myControls = new Control[3]; //建立一個含有3個Control引用的數組
- //注意:以上隻建立了3個引用,沒有建立實際的對象。
- myControls[0] = new Button(); //建立對象
- myControls[1] = new TextBox();
- myControls[2] = new ListView();
3、多元數組——矩陣數組
- double[,] myDoubles = new double[10,20]; //二維數組
- string[,,] myStrings = new string[3,4,5]; //三維數組
4、多元數組——鋸齒數組(jagged arrays)
- Point[][] myPonits = new Point[3][];
- myPoints[0] = new Point[10]; //注意這裡同樣隻是配置設定了10個引用,沒有建立對象
- myPoints[1] = new Point[5];
- myPoints[2] = new Point[20];
參考資料:《CLR via C#》