Reputation: 3251
My issue is to Find exact one Calendar object from a List Of(Calendar) by passing a particular date. I got to know about the predicate but not sure about passing parameter to it.
colorcode is List Of (Calendar) and calendar class has a property called DtmDate with which I want to compare and return the desired object.
Dim a As Calendar = colourcode.Find(AddressOf New Calendar.FindByDate)
I got the predicate samples from Google and reached till now. But not sure how to pass my parameter i.e. date to it.
Upvotes: 2
Views: 3882
Reputation: 106916
You will have to create your own predicate. You can do that using a lambda and by "lifting" local variables into it you can parametrize it. Here is an somewhat silly example for .NET 3.5/Visual Studio 2008:
Dim lookFor As String = "e"
Dim predicate = Function(s as String) s.Contains(lookFor)
Dim list As New List(Of String)
list.Add("alfa")
list.Add("beta")
list.Add("gamma")
list.Add("delta")
Dim foundString As String = list.Find(predicate)
Notice how you can change the value of lookFor
to search for other strings.
In .NET 4/Visual Studio 2010 Visual Basic has more expressive lambda expressions:
Upvotes: 3