Mega Code Archive

 
Categories / VB.Net Tutorial / Class Module
 

Use AddressOf to assign function to a delegate

public class Test     Private Delegate Function NumEmployeesDelegate() As Integer     Private Delegate Function GetNameDelegate() As String    public Shared Sub Main       Dim emp As New Employee()             Dim show_num As NumEmployeesDelegate         show_num = AddressOf Employee.GetNumEmployees         Console.WriteLine(show_num().ToString)           End Sub End class Public Class Employee     Public Shared Function GetNumEmployees() As Integer         Return 13     End Function     Public Overrides Function ToString() As String         Return "Employee"     End Function End Class 13