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 a Lookup<TKey, TSomething>
. If this proves to be the case, you can use ToLookup
to make one.
However, neither for ToLookup
nor for your code is there a query expression syntax available, unfortunately.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With