Dictionary的遍历
参考:https://docs.microsoft.com/zh-cn/dotnet/api/system.collections.generic.keyvaluepair-2?view=netframework-4.7
KeyValuePair<TKey,TValue> 结构
定义可以设置或检索的键/值对。
[System.Serializable] public struct KeyValuePair<TKey,TValue>
Dictionary<string, string> openWith =
new Dictionary<string, string>();
openWith.Add("txt", "notepad.exe");
openWith.Add("bmp", "paint.exe");
openWith.Add("dib", "paint.exe");
openWith.Add("rtf", "wordpad.exe");
Console.WriteLine(); foreach( KeyValuePair<string, string> kvp in openWith ) { Console.WriteLine("Key = {0}, Value = {1}", kvp.Key, kvp.Value); }
foreach( KeyValuePair<string, string> kvp in myDictionary )
{
Console.WriteLine("Key = {0}, Value = {1}", kvp.Key, kvp.Value);
}
KeyValuePair<TKey,TValue>(TKey, TValue) |
用指定的键和值初始化 KeyValuePair<TKey,TValue> 结构的新实例。 |
ToString() |
使用键和值的字符串表示形式返回 KeyValuePair<TKey,TValue> 的字符串表示形式。 |