How to: Invoke a Delegate Method (Visual Basic)
This example shows how to associate a method with a delegate and then invoke that method through the delegate.
Create the delegate and matching procedures
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
See also
التعاون معنا على GitHub
يمكن العثور على مصدر هذا المحتوى على GitHub حيث يمكنك أيضاً إضافة مشاكل وطلبات سحب ومراجعتها. للحصول على معلومات إضافية، اطلع على دليل المساهم لدينا.
الملاحظات
https://aka.ms/ContentUserFeedback.
قريبًا: خلال عام 2024، سنتخلص تدريجيًا من GitHub Issues بوصفها آلية إرسال ملاحظات للمحتوى ونستبدلها بنظام ملاحظات جديد. لمزيد من المعلومات، راجعإرسال الملاحظات وعرضها المتعلقة بـ