Orsi
Orsi

Reputation: 575

Select the max,min of nested lists vb.net

I have these objects

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

I can have more Type-s with their Speclimits values. I need to find the maximum of MaxValue. I can make it with a for each to check every time which number is bigger, but I thought maybe their is some linq with what this could be achievable. I found something like this in 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();

but I can't translate it to vb.net Any help is appreciated!

Upvotes: 0

Views: 221

Answers (1)

Tim Schmelter
Tim Schmelter

Reputation: 460360

I guess you want something like this:

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

Upvotes: 1

Related Questions