Linq Example 17 - Intersect

10:47 PM

Linq Query:

//Intersect
            string[] s1 = { "a", "b", "c", "d", "e", "f" };
            string[] s2 = { "d", "e", "f", "g", "h", "i" };
            // d,e,f common

            var intersect_s3 = s1.Intersect(s2);

            foreach (var t in intersect_s3)
            {
                Console.WriteLine(t);
            }


Output:


d
e
f

It will list out the common values in both the array.

0 comments:

Post a Comment