查找集合部分中最小属性的索引

本文关键字:属性 索引 集合部 查找 | 更新日期: 2023-09-27 18:10:57

我有一个类栏:

public class Bar
{
    public string Symbol { get; set; }
    public DateTime DateTime { get; set; }
    public double Open { get; set; }
    public double High { get; set; }
    public double Low { get; set; }
    public double Close { get; set; }
    public int Volume { get; set; }
}

和集合

minDataCollection<Bar>

我正在尝试找到具有最低bar的bar的索引。从当前条开始的n条"宽度"内的低条。问题是,如果我创建另一个大小为"width"的集合,并找到最小值,我将松散连接到主集合的索引。

查找集合部分中最小属性的索引

您可以使用LINQ的Select -with-an-index,然后使用MoreLINQ中的MinBy:

var index = collection.Select((value, index) => new { value, index })
                      .MinBy(pair => pair.value.Low).index;