Dictionary and KeyValuePair关系

来源:互联网 发布:淘宝网络推广类目 编辑:程序博客网 时间:2024/05/21 22:01

简单一句话: Dictionary 是 由 KeyValuePair结构 组成的集合 

The Dictionary<TKey, TValue>.Enumerator.Current property returns an instance of this type.

The foreach statement of the C# language (for each in C++, For Each in Visual Basic) requires the type of the elements in the collection. Since each element of a collection based on IDictionary<TKey, TValue> is a key/value pair, the element type is not the type of the key or the type of the value. Instead, the element type is KeyValuePair<TKey, TValue>. For example:

C#
C++
VB
 
foreach( KeyValuePair<string, string> kvp in myDictionary ){    Console.WriteLine("Key = {0}, Value = {1}", kvp.Key, kvp.Value);}

The foreach statement is a wrapper around the enumerator, which allows only reading from, not writing to, the collection.

0 0
原创粉丝点击