using System.Collections.Generic;
using System.Diagnostics;
public static void Main()
Console.WriteLine("Get difference between two unordered, not unique (duplicates) lists!");
Console.WriteLine("Solution by https://metadataconsulting.blogspot.com/2021/02/CSharp-dotNet-Get-difference-between-two-unordered-not-unique-lists-aka-duplicates-allowed-within-a-list-and-across-both-lists.html");
Stopwatch sw = new Stopwatch();
string[] arrA = new string[] { "1", "1", "2", "3", "4", "5", "9", "7", "7", "7" };
string[] arrB = new string[] { "1", "1", "2", "2", "3", "4", "5", "5", "5", "5" };
IEnumerable<string> Uniondifference = arrA.Union(arrB);
Console.WriteLine("RemoveRage Result = " + string.Join(",", Uniondifference) + " in " + sw.ElapsedTicks + " ticks.");
IEnumerable<string> AllArr = arrA.Concat(arrB);
var arrDups = AllArr.GroupBy(x=>x)
Console.WriteLine("RemoveRage Result = " + string.Join(",", arrDups) + " in " + sw.ElapsedTicks + " ticks.");
var arrDupsCnt = AllArr.GroupBy(x=>x)
.Select(y=> new { Element = y.Key, Counter = y.Count()})
Console.WriteLine("RemoveRage Result = " + string.Join(",", arrDupsCnt) + " in " + sw.ElapsedTicks + " ticks.");