Linq Example 16 - Union

10:44 PM
Linq Query:

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

            var union_s3 = s1.Union(s2);

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


Output:


a
b
c
d
e
f
g
h
i

Here Repeating d,e,f will not be in union_s3 .  It's equivalent to sql union.

0 comments:

Post a Comment