列表中包含单个键多个值的字典

时间:2015-08-19 14:39:13

标签: c# linq

我有一个linq查询,我想把它放在字典中。我的字典是

Dictionary<string, List<string>>

如何将查询放在定义的字典中?

...
...
select new
   {
     b.PropertyName             
     a.PropertyValue,
     a.PropertyOrder,
   }).Distinct().ToDictionary(x => x.PropertyName, 
    x => x.ToList() // The rest of the two values should be in the list
    );

1 个答案:

答案 0 :(得分:0)

select new {
b.PropertyName
a.PropertyValue,
a.PropertyOrder})
.Distinct()
.ToDictionary(key => key.PropertyName, 
value => new List<string>{ value.PropertyValue, value.PropertyOrder});