Recreating a Dictionary from an IEnumerable

Posted by learnerplates on Stack Overflow See other posts from Stack Overflow or by learnerplates
Published on 2010-04-14T10:31:36Z Indexed on 2010/04/14 10:32 UTC
Read the original article Hit count: 293

Filed under:
|

But some of the callers is the Dictionary's TryGetValue and ContainsKey and so require the result of the method to be a Dictionary, how can I convert the IEnumerable> into a Dictionary so that I can use TryGetValue ?

I've a method which at present returns an IEnumerable>.
I want to make it more generic by making it return an IEnumerable.

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");

© Stack Overflow or respective owner

Related posts about ienumerable

Related posts about collections