Using LINQ, can I verify a property has the same value for all objects?
I believe this would work:
public bool Validate(Crate crate)
{
return crate.Sections
.Select(x => x.Value.PixelsWide)
.Distinct()
.Count() < 2;
}
This will return true if crate.Sections
is empty as well as when the elements are all the same (which is the behavior of your current function).
Try this
var pixelsWide = rate.Sections.Values.First().PixelsWide;
bool result = crate.Sections.Values.All(x => x.PixelsWide == pixelsWide);