Find Object in List using LINQ

Hobbyist_programmer 621 Reputation points


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


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.


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

Accepted answer
  1. Viorel 114.5K Reputation points

    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

    sorry there is a typo. i mean 350.

    0 comments No comments