I have a method that returns an IEnumerable<KeyValuePair<string, ArrayList>>
, but some of the callers require the result of the method to be a dictionary. How can I convert the IEnumerable<KeyValuePair<string, ArrayList>>
into a Dictionary<string, ArrayList>
so that I can use TryGetValue
?
method:
public IEnumerable<KeyValuePair<string, ArrayList>> GetComponents()
{
// ...
yield return new KeyValuePair<string, ArrayList>(t.Name, controlInformation);
}
caller:
Dictionary<string, ArrayList> actual = target.GetComponents();
actual.ContainsKey("something");
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…