Bob Gatto Bob Gatto - 1 year ago 99
C# Question

How do I find equal values in multiple arrays?

In my program I ccould wind up with 2 or more arrays. In each array there are no duplicate values in a single array and the length of each array could be different.

What is the easy way to find if a value in array1 is equal to a value in array2 and equal to a value array3 and so on?

Answer Source

You can use LINQ. If you just need to know, if there are duplicates:

array1.Any(value1 => array2.Any(value2 => value2.Equals(value3)) &&array3.Any(....))

If you need the duplicated values itself, replace the first Any behind array 1 with a Where.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download