在元组列表上使用查找的谓词

Predicate to use Find on a List of Tuple

我有这个Dictionary:

Public TblDic As New Dictionary(Of String, List(Of Tuple(Of Date, Date, Decimal)))

我需要检索在第二项上具有最高日期的元组的第三项(十进制)。

我能够通过知道日期检索到第 3 个项目,但我无法检索到最高日期:

Dim LastDate As Date = Date.ParseExact("31/12/2016", "dd/MM/yyyy",
                                       New CultureInfo("it-IT"), DateTimeStyles.None)
Dim LastRate2 As Decimal = TblDic("Legali").Find(Function(D) D.Item2 = LastDate).Item3

另一种方法是将所有元组放入 DataTable 并使用 DataTable.Select 以这种方式检索小数字段:

Dim LastRate As Decimal = DT_Rates.Select("EndDate=MAX(EndDate)")(0).Field(Of Decimal)("Rate")

那么,我的问题是:
1) 是否可以在不知道最后日期的情况下使用 List.Find?
2) List.Find 和 DataTable.Select 之间的最佳实践是什么?

可以使用查找...也许?但我认为没有它就足够简单了。

Dim LastRate As Decimal = TblDic.
    SelectMany(Function(k) k.Value).
    OrderByDescending(Function(k) k.Item2).
    First().Item3

SelectMany() 将许多序列合并为一个序列。这种情况下的序列是字典的值,List(Of Tuple(Of Date, Date, Decimal))

OrderByDescending() 通过谓词对展平序列进行排序,其中 returns DateTuple(Of Date, Date, Decimal)。这在所有列表中排序 all Tuple(Of Date, Date, Decimal),因为它们被展平了

First() 在按日期降序

排序后取第一个 Tuple(Of Date, Date, Decimal)

Item3returnsTuple(Of Date, Date, Decimal)Decimal