I have two lists of the same object and I want to find the Union and Intersection of these lists based on a case-insensitive comparison of a property of the object.
For simplicity, let's call it a Person
, and I want to filter on the Person.Name
property.
What is the recommended way to do this? I'm hoping to keep the code in a single line of Linq.
Currently I'm doing the following:
public class Person { public string Name { get; set; } }
-
var people =
firstListOfPeople.Where(
p1 => p1.Name != null &&
secondListOfPeople
.Where(p2 => p2.Name != null)
.Select(p2 => p2.Name.ToUpper())
.Contains(p1.Name.ToUpper()));