Find Object in List using LINQ

Hobbyist_programmer 621 Reputation points
2021-03-15T13:02:28.717+00:00

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

VB
VB
An object-oriented programming language developed by Microsoft that is implemented on the .NET Framework. Previously known as Visual Basic .NET.
2,846 questions
0 comments No comments
{count} votes

Accepted answer
  1. Viorel 121.6K Reputation points
    2021-03-15T14:14:51.323+00:00

    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.

    0 comments No comments

1 additional answer

Sort by: Most helpful
  1. Hobbyist_programmer 621 Reputation points
    2021-03-15T13:05:06.757+00:00

    sorry there is a typo. i mean 350.

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.