1
我学习LINQ,我想知道是否可以简化以下LINQ查询...我现在就可以简化这个LINQ查询
我有两个字符串,我解析连接字符串来算使用每个单词。我想知道是否可以保留一个LINQ表达式,但不必复制from和let表达式中的string.Concat部分。
string sentence = "this is the first sentence";
string sentence2 = "this is the second sentence";
var res = from word in string.Concat(sentence, sentence2).Split()
let combinedwords = string.Concat(sentence, sentence2).Split()
select new { TheWord = word, Occurance = combinedwords.Count(x => x.Equals(word)) };
谢谢,那就是我一直在寻找的东西。 –