views:

28

answers:

1

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.

+1  A: 

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:

Martin Liversage
@Martin Thanks! I got one more solution here http://gist.github.com/295062
Antoops