Events
Mar 17, 9 PM - Mar 21, 10 AM
Join the meetup series to build scalable AI solutions based on real-world use cases with fellow developers and experts.
Register nowThis browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
This example shows how to associate a method with a delegate and then invoke that method through the delegate.
Create a delegate named MySubDelegate
.
Delegate Sub MySubDelegate(ByVal x As Integer)
Declare a class that contains a method with the same signature as the delegate.
Class class1
Sub Sub1(ByVal x As Integer)
MsgBox("The value of x is: " & CStr(x))
End Sub
End Class
Define a method that creates an instance of the delegate and invokes the method associated with the delegate by calling the built-in Invoke
method.
Protected Sub DelegateTest()
Dim c1 As New class1
' Create an instance of the delegate.
Dim msd As MySubDelegate = AddressOf c1.Sub1
' Call the method.
msd.Invoke(10)
End Sub
.NET feedback
.NET is an open source project. Select a link to provide feedback:
Events
Mar 17, 9 PM - Mar 21, 10 AM
Join the meetup series to build scalable AI solutions based on real-world use cases with fellow developers and experts.
Register nowTraining
Module
Call methods from the .NET Class Library using C# - Training
Use functionality in the .NET Class Library by calling methods that return values, accept input parameters, and more.
Documentation
Learn more about: Delegates (Visual Basic)
Delegate Statement - Visual Basic
Learn more about: Delegate Statement
Relaxed Delegate Conversion - Visual Basic
Learn more about: Relaxed Delegate Conversion (Visual Basic)