代码之家  ›  专栏  ›  技术社区  ›  Orsi

选择嵌套列表的最大值和最小值。网

  •  0
  • Orsi  · 技术社区  · 2 年前

    我有这些东西

    Public Class Class1
            Public Property Type As String
            Public Property SpecLimits As Limits
        End Class
    
        Public Class Limits
            Public Property MinValue As Double?
            Public Property MaxValue As Double?
        End Class
    

    我可以再吃一点 Type -和他们的 Speclimits 价值观我需要找到最大值。我可以用一个 for each 每次都要检查哪个数字更大,但我想也许他们的数字更大 linq 这是可以实现的。 我在一个房间里发现了类似的东西 c#

     var maxItem = emplist
    .Select((emp, index) => new 
    { 
        maxProject = emp.project
            .Select((proj, pIndex) => new{ proj, pIndex })
            .OrderByDescending(x => x.proj.ID)
            .First(),
        emp, index 
    })
    .OrderByDescending(x => x.maxProject.proj.ID)
    .First();
    

    但我不能把它翻译成 vb.net 感谢您的帮助!

    1 回复  |  直到 2 年前
        1
  •  1
  •   Tim Schmelter    2 年前

    猜测 你想要这样的东西:

    Dim minValue As Double = list.Min(Function(x) x.SpecLimits.MinValue)
    Dim maxValue As Double = list.Max(Function(x) x.SpecLimits.MaxValue)