question

Hobbyistprogrammer-7674 avatar image
0 Votes"
Hobbyistprogrammer-7674 asked ·

Find Object in List using LINQ

Hallo,

I am looking for an idea or easiest way to find a object which satisfies the criteria. for example below is my list .

77730-image.png



for example, if a have a value of 100, i want to look in the VMin and VMax column , if my value resides or equal in this range i want to get the P1, P2,P3, P4 values . With value of 100 i should get the 2nd row. if my value is 35 then i should get 4 th row.

Thanks

dotnet-visual-basic
image.png (7.0 KiB)
10 |1000 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Viorel-1 avatar image
0 Votes"
Viorel-1 answered ·

Something like this should work:

 Dim mydata as List(Of MyClass) = . . .
 Dim value as Integer = 100
    
 Dim found_object as MyClass = mydata.FirstOrDefault(Function(d) value >= d.VMin AndAlso value <= d.Vmax)
    
 If found_object IsNot Nothing Then
    Dim P1 = found_object.P1
    Dim P2 = found_object.P2
    Dim P3 = found_object.P3
    Dim P4 = found_object.P4
    . . .
 End If

Can be adjusted according to your real classes.

·
10 |1000 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Hobbyistprogrammer-7674 avatar image
0 Votes"
Hobbyistprogrammer-7674 answered ·

sorry there is a typo. i mean 350.

·
10 |1000 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.