![](/img/trans.png)
[英]Is there a structure identical to IEnumerable<KeyValuePair<TKey, TValue>>?
[英]Using Dictionary<TKey,TValue>(IEnumerable<KeyValuePair<TKey,TValue>>) Constructor in C#
我對如何使用感到困惑
Dictionary<TKey,TValue>(IEnumerable<KeyValuePair<TKey,TValue>>)
C#中字典類的構造函數。 一個工作示例將非常有幫助。
謝謝
薩蒂什·錢德拉
使用您提到的構造函數,您可以將已經存在的 Dictionary 作為參數傳遞。 例如:
Dictionary<int,string> firstDictionary = new Dictionary<int, string> { { 0, "0" }, { 1, "hallo" } };
Dictionary<int,string> secondDictionary;
void InitSecondDict()
{
secondDictionary = new Dictionary<int,string>(firstDictionary);
}
這個構造函數所做的是將元素從“firstDictionary”復制到新的 Dictionary<int,string>-object “secondDictionary”
Dictionary<string, string> openWith = new Dictionary<string, string>();
有關Micrsoft 文檔的更多信息和示例
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.