Допустим, у вас есть список строк.Сейчас есть разные возможности.
Решение 1: Используйте простую итерацию
//declare a dic of string, int
Dictionary<string, int> dic = new Dictionary<string,int>
//iterate loop
foreach (var i in lst)
{
if (dic.ContainsKey(i))
{
dic[i]++;
}
else
{
dic.Add(i, 1);
}
}
Решение 2: Используйте Linq Group By
//First group by the items and then transform the solution into dictionary
var dic = lst.GroupBy(x => x).ToDictionary(y => y.Key, z => z.Count());