
You want to use the AddressOf operator in your VB.NET program to reference a method and use it as the implementation for a delegate. With AddressOf, you can use the name of a function and use it where a delegate is required.

First, this program introduces the IsThreeLetters Function, which receives a String and returns a Boolean. This Function is used as a delegate. The Main entry point creates a List and adds three values to it. Then, the List.Find Function is used to find the first three-letter String in the List instance. The AddressOf operator is used and it references the IsThreeLetters Function.
This VB example shows the AddressOf operator. It uses AddressOf to use a Function as a delegate.
Program that uses AddressOf [VB.NET]
Module Module1
Function IsThreeLetters(ByVal value As String) As Boolean
Return value.Length = 3
End Function
Sub Main()
Dim list As List(Of String) = New List(Of String)
list.Add("mouse")
list.Add("horse")
list.Add("dog")
Dim value As String = list.Find(AddressOf IsThreeLetters)
Console.WriteLine(value)
End Sub
End Module
Output
dog
In the C# language, you do not need an operator like AddressOf. Instead, you can simply use the method name directly as the delegate. The AddressOf operator may actually be less confusing as it introduces the context in which the method name should be referenced in. It tells you that the method name is just used to acquire a memory address.
The AddressOf operator provides an excellent way for you to reference an existing Function and turn it into a delegate. This means you do not need to use lambda expression syntax, and can use existing functions.
Lambda Expression VB.NET Tutorials