Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to use contains method to a specific field value in a list? 1

Status
Not open for further replies.

WomanPro

Programmer
Nov 1, 2012
180
0
0
GR
I have a list that holds sturctures. So each element of the list consist of fields. Is there a way to use contains method to look directly for a specific field value?
If yes may somebody give an example? Thank you so much in advanced.
 
Try this:

Say you have a Fruit structure:

Private Structure Fruit
Public Name As String​
Public Color As String​
End Structure

Then, you have a List called FruitBowl:

Dim FruitBowl as List(Of Fruit)

'fill FruitBowl with Fruit...

To see if FruitBowl Contains Fruit that is red:

FruitBowl.Contains(Function(x), x.Color="Red")


I used to rock and roll every night and party every day. Then it was every other day. Now I'm lucky if I can find 30 minutes a week in which to get funky. - Homer Simpson

Arrrr, mateys! Ye needs ta be preparin' yerselves fer Talk Like a Pirate Day!
 
Thank you so much
That worked for me
Code:
Dim TmpFruit As New Fruit
TmpFruit = FruitBowl.Find(Function(x) x.Color.Contains("Red"))
If TmpFruit.Color Is Nothing Then
      MsgBox("nothing finded")
End If

May you explain me what exaclty does Function(x) please? I didn't created any function and it worked!!! So what exactly does it do?
Thank you so much in advanced.
 
I found about delegates and lamda expressions. So I need to study about them because I'm not familiar with. However, I have almost understood. Thank you so much in advanced. You saved me.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top