using System; using System.Collections.Generic; using System.Linq; public class Test { public static void Main() { var list1 = new List() { 1, 2, 3, 4 }; var list2 = new List() { 2, 3, 5, 6, 7, 8 }; var list3 = new List() { 3, 4, 5 }; var all = new HashSet(list1.Concat(list2).Concat(list3)); int?[] l1Result = new int?[all.Count]; int?[] l2Result = new int?[all.Count]; int?[] l3Result = new int?[all.Count]; int idx = 0; foreach (int val in all) { if (list1.BinarySearch(val) >= 0) l1Result[idx] = val; if (list2.BinarySearch(val) >= 0) l2Result[idx] = val; if (list3.BinarySearch(val) >= 0) l3Result[idx] = val; idx += 1; } Console.WriteLine(string.Join("\t", l1Result.Select(i => !i.HasValue ? "NULL" : i.Value.ToString()).ToArray())); Console.WriteLine(string.Join("\t", l2Result.Select(i => !i.HasValue ? "NULL" : i.Value.ToString()).ToArray())); Console.WriteLine(string.Join("\t", l3Result.Select(i => !i.HasValue ? "NULL" : i.Value.ToString()).ToArray())); } }