关于VB.NET的委托

来源:互联网 发布:淘宝商城耐克男运动鞋 编辑:程序博客网 时间:2024/04/29 02:45

 

委托可以认为是一类方法签名一致的方法抽象类。

委托对象必须由签名一致的方法实例化,而通过调用委托对象可以调用实例化委托对象的方法。

 

 

Public Class Form1    Public Delegate Function addMethod(ByVal x, ByVal y) As Integer    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click        Dim a As addMethod        Dim b As Tdelegate        b = New Tdelegate()        a = New addMethod(AddressOf b.add)        'TextBox1.Text = TextBox1.Text + a(3, 9).ToString        'TextBox1.Text = TextBox1.Text + (New addMethod(AddressOf New Tdelegate().add))(3, 9).ToString        TextBox1.Text = TextBox1.Text + New addMethod(AddressOf New Tdelegate().add).Invoke(3, 9).ToString    End SubEnd ClassPublic Class Tdelegate    Public Function add(ByVal x, ByVal y) As Integer        Return x + y    End FunctionEnd Class


 

原创粉丝点击