Is there a way to write the ToDictionary statement below using the SQL-ish Linq syntax?
public class KeyedType
{
public string Name { get; set; }
public string Value { get; set; }
}
Dictionary<string,List<KeyedType>> groups =
list.GroupBy((g) => g.Name)
.ToDictionary(g => g.Key, g => g.ToList());
Whenever you find yourself with a
Dictionary<TKey, List<TSomething>>, you may find you can happily use aLookup<TKey, TSomething>. If this proves to be the case, you can useToLookupto make one.However, neither for
ToLookupnor for your code is there a query expression syntax available, unfortunately.