有一種簡單的方法來計算列表中的所有元素出現在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