employeeList has 5 employee records so to filter only those empoyees name having in employeeList2 -
List<Employee> employeeList = new List<Employee>() { new Employee() { Name = "Ashish"},
new Employee() { Name = "Aman"},
new Employee() { Name = "Soni"},
new Employee() { Name = "Akash"},
new Employee() { Name = "Rahul"},
new Employee() { Name = "Mukesh"}};
var employeeList2 = new List<Employee>() { new Employee() { Name = "Ashish"}, new Employee() { Name = "Mukesh" } };
var filterData = employeeList.Where(x => employeeList2.Any(y => y.Name.Equals(x.Name)));
Output - Ashish and Mukesh records
List<Employee> employeeList = new List<Employee>() { new Employee() { Name = "Ashish"},
new Employee() { Name = "Aman"},
new Employee() { Name = "Soni"},
new Employee() { Name = "Akash"},
new Employee() { Name = "Rahul"},
new Employee() { Name = "Mukesh"}};
var employeeList2 = new List<Employee>() { new Employee() { Name = "Ashish"}, new Employee() { Name = "Mukesh" } };
var filterData = employeeList.Where(x => employeeList2.Any(y => y.Name.Equals(x.Name)));
Output - Ashish and Mukesh records
No comments:
Post a Comment