有一种简单的方法来计算列表中的所有元素出现在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]);
}
}
+1:我花了一段时间才弄清楚,的getMethods()只是你的事情列表。 :) – 2009-07-16 18:05:45
是的,我想到了这一点,并决定让它更具可读性。谢谢,虽然我误解了这个问题。它说要计算“所有元素”.. ooops。这应该仍然有用。 – 2009-07-16 18:06:55