C#中Dictionary字典取值

// Create a new dictionary of strings, with string keys.
//
Dictionary<stringstringopenWith =
new Dictionary<stringstring>();
 
// When you use foreach to enumerate dictionary elements,
// the elements are retrieved as KeyValuePair objects.
Console.WriteLine();
foreachKeyValuePair<stringstringkvp in openWith )
{
Console.WriteLine("Key = {0}, Value = {1}",
kvp.Keykvp.Value);
}
// To get the values alone, use the Values property.
Dictionary<stringstring>.ValueCollection valueColl =
openWith.Values;
 
// The elements of the ValueCollection are strongly typed
// with the type that was specified for dictionary values.
Console.WriteLine();
foreachstring in valueColl )
{
Console.WriteLine("Value = {0}"s);
}

猜你喜欢

转载自www.cnblogs.com/kglovekk/p/9556779.html