I want to compare two collections. I believe that I am doing it the long way (codewise). I want to find what numbers might be missing from a collection when compared to another collection. Order is unimportant.
class Program
{
static void Main(string[] args)
{
List< int> x = new List<int>() { 1 };
List< int> y = new List<int>() { 1, 2, 3 };
//find what numbers (if any) that x needs to have in order to have an identical list as y (order not important)
List<int> missingNumbers = new List<int>();
foreach (var number in y)
{
if (!x.Contains(number))
{
missingNumbers.Add(number);
}
}
foreach (var missingNumber in missingNumbers)
{
x.Add(missingNumber);
}
}
}