I want to compare 2 arrays and check if they have 1 or more equal elements then I want to print this element like:
array1[a ,b ,c , d, e]
array2[e, r, t , a, v]
Console.println["a"]
I want to compare 2 arrays and check if they have 1 or more equal elements then I want to print this element like:
array1[a ,b ,c , d, e]
array2[e, r, t , a, v]
Console.println["a"]
You could use this
var commonElements = array1.Intersect(array2).ToArray();
If commonElements.Length>0
the arrays array1
and array2
have at least one common element.
Then you can print the common elements by just iterating through the items of the commonElements
array.
foreach(var commonElement in commonElements)
Console.WriteLine(commonElement);