public static void CountAllDoubles()
{
// String listesi.
List<String> listOfStrings = new List<String>{ "AAA", "BBB", "CCC", "AAA", "CCC", "AAA", "DDD" };
var query = listOfStrings.GroupBy(
element => element,
(element, elements) => new
{
Key = element,
Count = elements.Count(),
});
Console.WriteLine("Counting all occurrences including single ones:");
foreach (var result in query)
{
Console.WriteLine("\tString: {0} Number of occurrences: {1}", result.Key, result.Count);
}
Console.WriteLine("\nCounting only multiple occurrences:");
foreach (var result in query.Where(a => { return a.Count > 1; }))
{
Console.WriteLine("\tString: {0} Number of occurrences: {1}", result.Key, result.Count);
}
}