詳細介紹用C#描述資料結構2:Array的圖文代碼執行個體

來源:互聯網
上載者:User

  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

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.