相关疑难解决方法(0)

一种计算列表中出现次数的方法

有没有一种简单的方法可以将列表中所有元素的出现次数计入C#中的相同列表?

像这样的东西:

using System;
using System.IO;
using System.Text.RegularExpressions;
using System.Collections.Generic;
using System.Linq;

string Occur;
List<string> Words = new List<string>();
List<string> Occurrences = new List<string>();

// ~170 elements added. . . 

for (int i = 0;i<Words.Count;i++){
    Words = Words.Distinct().ToList();
    for (int ii = 0;ii<Words.Count;ii++){Occur = new Regex(Words[ii]).Matches(Words[]).Count;}
         Occurrences.Add (Occur);
         Console.Write("{0} ({1}), ", Words[i], Occurrences[i]);
    }
}
Run Code Online (Sandbox Code Playgroud)

c# list count match .net-3.5

45
推荐指数
3
解决办法
9万
查看次数

标签 统计

.net-3.5 ×1

c# ×1

count ×1

list ×1

match ×1