두 시퀀스가 같은지 확인하려면 SequenceEqual() 메서드를 사용하십시오.
먼저 시퀀스를 설정합니다.
Employee emp1 = new Employee { EmployeeRank = 4, EmpName = "Amit", EmpMarks = 90 }; Employee emp2 = new Employee { EmployeeRank = 5, EmpName = "Raman", EmpMarks = 95 }; List<Employee> employee1 = new List<Employee> { emp1, emp2 }; List<Employee> employee2 = new List<Employee> { emp1, emp2 };
이제 시퀀스가 동일한지 여부를 찾으십시오.
employee1.AsQueryable().SequenceEqual(employee2);
다음은 결과를 보여주는 예입니다.
예
using System; using System.Linq; using System.Collections.Generic; public class Demo { public static void Main() { Employee emp1 = new Employee { EmployeeRank = 4, EmpName = "Amit", EmpMarks = 90 }; Employee emp2 = new Employee { EmployeeRank = 5, EmpName = "Raman", EmpMarks = 95 }; List<Employee> employee1 = new List<Employee> { emp1, emp2 }; List<Employee> employee2 = new List<Employee> { emp1, emp2 }; bool res = employee1.AsQueryable().SequenceEqual(employee2); Console.WriteLine("Lists are equal? = "+res); } } public class Employee { public int EmployeeRank { get; set; } public string EmpName { get; set; } public int EmpMarks { get; set; } }
출력
Lists are equal? = True