Array是.NET提供的最基礎的資料集合,通過索引直接存取集合元素。提供一維或多維資料存放區,並支援諸如,查詢,搜尋,排序,複製等操作。
提供的主要介面,根據語義劃分,主要包括:
也可以打百度腦圖查看:
http://naotu.baidu.com/file/f879a94fe2163c365cc22f4e4bbcc7dc
一維數組聲明,建立,初始化:
1)直接在初始化器內進行:
int[] mp = new int[6] { -50, -30, -10, 10, 30, 50 };
2)分別賦值:
mp[0] = -50; mp[1] = -30; mp[2] = -10; mp[3] = 10; mp[4] = 30; mp[5] = 50;
如所示,一維圖的編號分別為0,1,2,3,4,5
多維(例如二維)數組聲明,建立,初始化:(如所示,二維的編號分別為0,1,2,3,4,5)
int[,] point = new int[2, 6] { { -50, -30, -10, 10, 30, 50 },//第0維 { 50, 30, 10, 10, 30, 50 }//第1維 };
分別初始化:
//點0 point[0, 0] = -50; point[1, 0] = 50; //點1 point[0, 1] = -30; point[1, 1] = 30; //點2 point[0, 2] = -10; point[1, 2] = 10; //點3 point[0, 3] = 10; point[1, 3] = 10; //點4 point[0, 4] = 30; point[1, 4] = 30; //點5 point[0, 5] = 50; point[1, 5] = 50;
分別比較一維和多維,介面方法的語義區別:
//擷取某維的元素個數 int mpLen0 = mp.GetLength(0);//6 int pointLen0 = point.GetLength(0);//2 int pointLen1 = point.GetLength(1);//6 //擷取某個維度下標最大值 int mpUpperBound = mp.GetUpperBound(0); //5 int pointUpperBound0 = point.GetUpperBound(0);//1 int pointUpperBound1 = point.GetUpperBound(1);//5 //擷取某個維度下標最小值 int mpLowBound = mp.GetLowerBound(0);//0 int pointLowBound0 = point.GetLowerBound(0);//0 int pointLowBound1 = point.GetLowerBound(1);//0 //擷取所有維數的元素總數 int mpLen = mp.Length;//6 int pointLen = point.Length;//12 //擷取維數 int mpRank = mp.Rank;//1 int pointRank = point.Rank;//2
總結
1 Array在編譯時間必須確定元素每一維度元素個數,這是它最大的缺陷,對於運行時才能確定某個維度元素個數的情況,這個資料結構是不能滿足條件的!
2 Array建立時的類型為強型別,必須指定。
下載Array思維導圖地址:
http://download.csdn.net/detail/daigualu/9772336
測試源碼下載地址:
http://download.csdn.net/my