An extension method on a collection named MeasurementCollection checks if the property Template.Frequency (Enum) of each item has the same value.
public static bool IsQuantized(this MeasurementCollection items)
{
return (from i in items
select i.Template.Frequency)
.Distinct()
.Count() == 1;
}
edit
info about underlying classes
MeasurementCollection : ICollection<IMeasurement>
IMeasurement
{
IMeasurementTemplate Template { get; }
......
}
Is this a correct approach or is there an easier solution already in Linq?
This method will be used intense in the application.
Have you got tips to take with me, back to the drawing board?
Edit: to address Timwi’s concerns about 3 enumerators:
Which still uses 2 enumerators. Not an issue for the average
List<>, but for a DB query it might pay to use the less readable: