Just put all the
Strings
you produced into a List and then let loose the power of
Enumerable.Distinct(Of TSource)-Methode (IEnumerable(Of TSource))[
^].
[Edit]
While taking set differences may also have been an option I tried a different approach from above utilizing LinQ queries:
public static void CountAllDoubles()
{
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);
}
}
[/Edit]
Regards,
Manfred
As a side note, I just had an opportunity to use this today.