C# 中列表和字典之間有什麼區別?
字典是 C# 中的一組鍵和值。Dictionary<TKey, TValue> 包含在 System.Collection.Generics 名稱空間中。字典是一種泛型型別,如果您嘗試查詢一個不存在的鍵,它將返回一個錯誤。
列表集合是一種泛型類,可以儲存任何資料型別以建立列表。
列表是一組項——
List<string> myList = new List<string>() {
"Maths",
"English",
" Science"
};字典是一組鍵值對。
Dictionary<string, int> d = new Dictionary<string, int>();
d.Add("squash", 1);
d.Add("football", 2);
d.Add("rugby", 3);遍歷列表更容易、更快速,而且可以使用列表輕鬆地使用索引訪問元素。
廣告
資料結構
網路
關係型資料庫管理系統
作業系統
Java
iOS
HTML
CSS
Android
Python
C 程式設計
C++
C#
MongoDB
MySQL
Javascript
PHP