Given the following code from a Microsoft example:
public class EngineMeasurementCollection : Collection<EngineMeasurement> { public EngineMeasurementCollection() { Add(new EngineMeasurement { Speed = 1000, Torque = 100, Power = 20 }); Add(new EngineMeasurement { Speed = 2000, Torque = 160, Power = 60 }); Add(new EngineMeasurement { Speed = 3000, Torque = 210, Power = 125 }); Add(new EngineMeasurement { Speed = 4000, Torque = 220, Power = 160 }); Add(new EngineMeasurement { Speed = 5000, Torque = 215, Power = 205 }); Add(new EngineMeasurement { Speed = 6000, Torque = 200, Power = 225 }); Add(new EngineMeasurement { Speed = 7000, Torque = 170, Power = 200 }); } } public class EngineMeasurement { public int Speed { get; set; } public int Torque { get; set; } public int Power { get; set; } }
How to get minimum / maximum speed or torque or power. I need this to set the scale on the chart I'm doing (more precisely, the WPF Toolkit Chart). I suppose I might have a method inside the EngineMeasurementCollection that iterates through each EngineMeasurement and looks at Power (or Speed), but I suspect there is a much simpler way? The Collection class has some kind of Min method, but note, I'm not trying to get the minimum of the collection (I'm not sure what this will mean in this case), but rather the minimum of a certain property (speed). I have seen using Collection.Min with functors. Is there something you could do there? Or with Link? I'm interested in all the ways. Thanks, Dave
Bonus question (maybe this will be obvious to me with the answer to min / max). What are the options to determine if a value is (for example, Speed ββis already in the collection). This is not clear from this example, but it may be that if you already have data for a given independent variable (e.g. time), you no longer need to. So, is there something like Collection.Contains ("indicate property of interest to you")?
source share