2
从IEnumerable <KeyValuePair <>>重新创建字典
我有一个返回的方法IEnumerable<KeyValuePair<string, ArrayList>>,但是某些调用者要求该方法的结果为字典。如何将转换IEnumerable<KeyValuePair<string, ArrayList>>为Dictionary<string, ArrayList>以便使用TryGetValue? 方法: public IEnumerable<KeyValuePair<string, ArrayList>> GetComponents() { // ... yield return new KeyValuePair<string, ArrayList>(t.Name, controlInformation); } 呼叫者: Dictionary<string, ArrayList> actual = target.GetComponents(); actual.ContainsKey("something");