I am trying to intersect two collections. I've got two lists listed below in a code snippet.
This is my output:
Intersection
1
Why is only one value found? Is it the expected behavior or I am doing something wrong?
I expect my output looks like this:
Intersection
1
1
1
1
My code:
// Collection initialization
List<int> list1 = new List<int> { 1,1,1,1 };
List<int> list2 = new List<int> { 1,1,1,1,1,1,1,1,1,1,1 };
foreach (int q in list1)
Console.WriteLine("list1: " + q);
Console.WriteLine("------------------");
foreach (int q in list2)
Console.WriteLine("list2: " + q);
Console.WriteLine("------------------");
Console.WriteLine("Intersection");
IEnumerable<int> both = list1.Intersect(list2);
foreach (int a in both)
Console.WriteLine(a);
Console.ReadLine();
Console.Clear();