I want to compare the following two lists on a combination of two properties (Country and City).
When compared, India-Chennai is present in both the lists and have the same value (1). Similarly, UK-London also is present in both the lists and have the same value (3). However, though USA-New York is present on both the lists, their values are not matching (2 in list1 and 5 in list 2).
Please help me write the shortest possible linq expression to select only '2-USA-New York' from list1 as its value is not matching with list2 ('5-USA-New York').
void Main()
{
List<A> list1 = new List<A> {
new A { Country = "India", City = "Chennai", Value = 1 },
new A { Country = "USA", City = "New York", Value = 2 },
new A { Country = "UK", City = "London", Value = 3 }
};
List<A> list2 = new List<A> {
new A { Country = "India", City = "Chennai", Value = 1 },
new A { Country = "USA", City = "New York", Value = 5 },
new A { Country = "UK", City = "London", Value = 3 }
};
list1.Dump();
list2.Dump();
}
class A
{
public int Value { get; set; }
public string Country { get; set; }
public string City { get; set; }
}