Rud*_*ser 23
您可以使用Hashtable该类,或者Dictionary<TKey, TValue>如果您知道要存储的特定类型,则可以使用该类.
例:
// Loose-Type
Hashtable hashTable = new Hashtable();
hashTable.Add("key", "value");
hashTable.Add("int value", 2);
// ...
foreach (DictionaryEntry dictionaryEntry in hashTable) {
Console.WriteLine("{0} -> {1}", dictionaryEntry.Key, dictionaryEntry.Value);
}
// Strong-Type
Dictionary<string, int> intMap = new Dictionary<string, int>();
intMap.Add("One", 1);
intMap.Add("Two", 2);
// ..
foreach (KeyValuePair<string, int> keyValue in intMap) {
Console.WriteLine("{0} -> {1}", keyValue.Key, keyValue.Value);
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
39504 次 |
| 最近记录: |