Questions tagged «idictionary»

2
从IEnumerable <KeyValuePair <>>重新创建字典
我有一个返回的方法IEnumerable&lt;KeyValuePair&lt;string, ArrayList&gt;&gt;,但是某些调用者要求该方法的结果为字典。如何将转换IEnumerable&lt;KeyValuePair&lt;string, ArrayList&gt;&gt;为Dictionary&lt;string, ArrayList&gt;以便使用TryGetValue? 方法: public IEnumerable&lt;KeyValuePair&lt;string, ArrayList&gt;&gt; GetComponents() { // ... yield return new KeyValuePair&lt;string, ArrayList&gt;(t.Name, controlInformation); } 呼叫者: Dictionary&lt;string, ArrayList&gt; actual = target.GetComponents(); actual.ContainsKey("something");
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.