字典與陣列在 C# 中有什麼區別?
字典
字典是 C# 中的鍵值集合。字典包含在 System.Collection.Generics 名稱空間中。
宣告字典的程式碼:
IDictionary<int, int> d = new Dictionary<int, int>();
新增元素的程式碼:
IDictionary<int, int> d = new Dictionary<int, int>(); d.Add(1,97); d.Add(2,89); d.Add(3,77); d.Add(4,88);
陣列
陣列儲存相同型別元素的固定大小的順序集合。它由連續的記憶體位置組成。最低地址對應於第一個元素,最高地址對應於最後一個元素。
定義陣列的程式碼:
int[] arr = new int[5];
初始化並向陣列中設定元素
int[] arr = new int[10] {3, 5, 35, 87, 56, 99, 44, 36, 78};
廣告
資料結構
網路
關係型資料庫管理系統
作業系統
Java
iOS
HTML
CSS
Android
Python
C 程式設計
C++
C#
MongoDB
MySQL
Javascript
PHP