Ваш запрос возвращает немного странный набор результатов:
TheWord Occurrence
this 1
is 2
the 2
first 1
sentencethis 1
is 2
the 2
second 1
sentence 1
Это то, что вы хотите, или вы бы предпочли, чтобы результаты были более похожими на это?
TheWord Occurrence
this 2
is 2
the 2
first 1
sentence 2
second 1
Чтобы получить эти результаты, вы можете сделать что-то вроде этого:
var res = from word in sentence.Split()
.Concat(sentence2.Split())
group word by word into g
select new { TheWord = g.Key, Occurrence = g.Count() };
Другой вариант; лучшая (теоретическая) производительность, но менее читаемая:
var res = sentence.Split()
.Concat(sentence2.Split())
.Aggregate(new Dictionary<string, int>(),
(a, x) => {
int count;
a.TryGetValue(x, out count);
a[x] = count + 1;
return a;
},
a => a.Select(x => new {
TheWord = x.Key,
Occurrence = x.Value
}));