所以我在txt文件中有任意文本,我需要找到10个最常用的单词.我该怎么办?我想我应该阅读从点到点的句子并把它放到一个数组中,但不知道该怎么做.
你可以用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)
| 归档时间: |
|
| 查看次数: |
2498 次 |
| 最近记录: |