作者:vuefine 文獻: - Data Structures and Algorithms Using C# | Michael Mcmillan 平臺:.NET 2.0+
Array是.NET提供的最基礎的數據集合,通過索引直接訪問集合元素。提供一維或多維數據存儲,并支持諸如,查詢,搜索,排序,復制等操作。 提供的主要接口,根據語義劃分,主要包括:

一維數組聲明,創建,初始化: 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
新聞熱點
疑難解答