c# - 识别对象列表中属性的最小值和最大值

标签 c# .net

我有这门课

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 MinMax 方法作为起点。

关于c# - 识别对象列表中属性的最小值和最大值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18923651/

相关文章:

.net - 应用程序符合 FIPS 140 标准意味着什么?

c# - 在运行时更改默认的 app.config

c# - Neo4j 客户端匹配 Id 列表

c# - 如何在用户登录但后来从数据库中删除时清除 session

c# - 如何通过 Assembly 访问泛型类型来解决它们?

c# - ASP.NET - 无法将更改从 GridView 保存到数据库

c# - WinForms 中的下拉绑定(bind)

c# - 是否有带有 T 检验和 p 值的 .Net Statistics 库?

c# - 在 ASP.NET MVC 中获取 MembershipUser

C#如何在从ASCII编码后写入字符串部分?