Can someone please explain why these two methods are returning different values?
List<CustomerSummary> summaries = new List<CustomerSummary>();
for (var i = 0; i < 10; i++)
{
var summary = new CustomerSummary() { ID = 1, Name = "foo", balance = 50.00 };
if (!summaries.Contains(summary))
summaries.Add(summary);
}
-
List<CustomerSummary> summaries = new List<CustomerSummary>();
for (var i = 0; i < 10; i++)
{
var summary = new CustomerSummary() { ID = 1, Name = "foo", balance = 50.00 };
if (!summaries.Any(s=> s.ID == summary.ID))
summaries.Add(summary);
}
The first method has 10 items in the list while the second has 1. Why does the first ( Contains() ) method never evaluate as true?
What I'm trying to ask is why are 2 objects of the same type with the same values for each property not evaluating as equivalent (in the first method)?