如何在文本中找到10个最常用的单词

Vit*_*kis -3 c# text

所以我在txt文件中有任意文本,我需要找到10个最常用的单词.我该怎么办?我想我应该阅读从点到点的句子并把它放到一个数组中,但不知道该怎么做.

Jan*_*neP 9

你可以用Linq实现它.尝试这样的事情:

var words = "two one three one three one";
var orderedWords = words
  .Split(' ')
  .GroupBy(x => x)
  .Select(x => new { 
    KeyField = x.Key, 
    Count = x.Count() })
  .OrderByDescending(x => x.Count)
  .Take(10);
Run Code Online (Sandbox Code Playgroud)