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. 이것은 각기 다른 요소의 출현을 세는 것이 매우 우아합니다. –
어떨까요? 좋아요? – CodeFusionMobile
FindAll은 술어와 일치하는 원본 목록의 요소 목록을 반환하므로 각 고유 요소에 대해 한 번 수행해야 해당 요소의 수를 찾을 수 있습니다. –