Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

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!

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

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)
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading