यह जाँचने के लिए कि दो क्रम बराबर हैं या नहीं, 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