Sunday, June 15, 2008

LINQ ToDictionary

If you want to convert an IEnumerable to a dictionary using LINQ then do:

Dictionary<string, object> dict = myList.ToDictionary(a => a.MyString, a => a.MyObject);

2 comments:

  1. Yeah, that's exactly what I needed!
    thanks

    ReplyDelete
  2. Super, works perfectly!

    ReplyDelete