51
1
using System;
2
using System.Linq;
3
using System.Collections.Generic;
4
5
public class Program
6
{
7
public static void Main()
8
{
9
IList<Student> studentList1 = new List<Student>() {
10
new Student() { StudentID = 1, StudentName = "John", Age = 18 } ,
11
new Student() { StudentID = 2, StudentName = "Steve", Age = 15 } ,
12
new Student() { StudentID = 3, StudentName = "Bill", Age = 25 } ,
13
new Student() { StudentID = 5, StudentName = "Ron" , Age = 19 }
14
};
15
16
IList<Student> studentList2 = new List<Student>() {
17
new Student() { StudentID = 3, StudentName = "Bill", Age = 25 } ,
18
new Student() { StudentID = 5, StudentName = "Ron" , Age = 19 }
19
};
20
21
var result = studentList1.Union(studentList2,new StudentComparer());
22
23
foreach(var std in result)
24
Console.WriteLine(std.StudentName);
Cached Result
1 2 3 4 5,
6 7 8 9 10,
11 12 13 14 15,
16 17 18 19 20,
21 22 23 24 25,
26
6 7 8 9 10,
11 12 13 14 15,
16 17 18 19 20,
21 22 23 24 25,
26