【发布时间】:2018-10-21 22:35:03
【问题描述】:
模型是:
public class Word
{
public int Id { get; set; }
public IList<UsedCount> UsedCount { get; set; }
}
public class UsedCount
{
public int Id { get; set; }
public string Key { get; set; }
public int Value { get; set; }
}
有语言列表:
// Actually there are more then 3 langs used
List<string> langList = new List<string> { "en", "pl", "de" };
还有单词列表
List<Word> words = new List<Words>();
我计算每个单词在每种语言中使用了多少次。 我需要让所有单词总共使用超过 100 次,不管是哪种语言:
renewingIteration = Words.Where(p => (
p.UsedCount.FirstOrDefault(count => count.Key == langList[0]).Value +
p.UsedCount.FirstOrDefault(count => count.Key == langList[1]).Value +
p.UsedCount.FirstOrDefault(count => count.Key == langList[2]).Value
//... and so on
> 100)
我怎样才能使它更简单并避免手动编写 langList[0], langList[1]...?
【问题讨论】: