C# 數組 使用速查

1、一維數組(值類型)

  1. int[] myIntegers; //申明一個數組的引用 
  2. myIntegers = new int[100]; //創建一個含有100個int元素的數據

2、一維數組(引用類型)

  1. Control[] myControls; //聲明一個數組引用
  2. myControls = new Control[3]; //創建一個含有3個Control引用的數組
  3. //注意:以上只創建了3個引用,沒有創建實際的對象。
  4. myControls[0] = new Button(); //創建對象
  5. myControls[1] = new TextBox();
  6. myControls[2] = new ListView();

3、多維數組——矩陣數組

  1. double[,] myDoubles = new double[10,20]; //二維數組
  2. string[,,] myStrings = new string[3,4,5]; //三維數組

4、多維數組——鋸齒數組(jagged arrays)

  1. Point[][] myPonits = new Point[3][];
  2. myPoints[0] = new Point[10]; //注意這裏同樣只是分配了10個引用,沒有創建對象
  3. myPoints[1] = new Point[5];
  4. myPoints[2] = new Point[20]; 
參考資料:《CLR via C#》

 

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章