我有这门课
class TimeSeriesDataPoint
{
public int HistorianID { get; set; }
public string Time { get; set; }
public double Value { get; set; }
public int Quality { get; set; }
}
和这个类的对象列表数组
List<TimeSeriesDataPoint>[] Curves = new List<TimeSeriesDataPoint>[numberOfCurves];
每个曲线都有大约 1000 个 TimeSeriesDataPoint 对象的列表。我需要为每条曲线(曲线 [0]、曲线 [1] 等)确定属性“值”的最小值和最大值。
我可以使用 List 类中的 Min 和 Max 方法吗?有人可以帮我吗?
人南
最佳答案
foreach (var curve in Curves)
{
double min = curve.Min(x => x.Value);
double max = curve.Max(x => x.Value);
// do something with your min, max, and curve
}
如果性能是个问题,您可以自己实现,一次计算最小值和最大值。您可以使用 Mono's implementation Min
和 Max
方法作为起点。
关于c# - 识别对象列表中属性的最小值和最大值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18923651/