Union() মেথড দুটি সিকোয়েন্সের ইউনিক এলিমেন্টগুলো মিলিয়ে একটি সিকোয়েন্স রিটার্ন করে (সেট ইউনিয়ন)। ডুপ্লিকেট অটোমেটিক রিমুভ হয়।
উদাহরণ
using System;
using System.Linq;
using System.Collections.Generic;
public class Demo
{
public static void Main()
{
int[] arr1 = { 29, 40, 15, 55, 70, 30, 90 };
int[] arr2 = { 30, 36, 40, 18, 15, 55, 75 };
IEnumerable res = arr1.AsQueryable().Union(arr2);
foreach (int a in res)
Console.WriteLine("{0} ", a);
}
}
আউটপুট
29 40 15 55 70 30 90 36 18 75
অর্ডার: প্রথম সিকোয়েন্সের এলিমেন্টগুলো প্রথমে, তারপর দ্বিতীয় সিকোয়েন্সের यুনিক এলিমেন্টগুলো। কাস্টম কমপারার ব্যবহার করা যায়।