我对委托的理解(VB.NET)
我刚接触委托,我觉的委托就相当于一个函数指针.
下面是我写的一个关于委托最简单的例子:
Form1是指一个窗体,TextBox1是指一个TextBox控件
下面是我写的一个关于委托最简单的例子:
Form1是指一个窗体,TextBox1是指一个TextBox控件
Private Function HelloWorld() As String
Return "Hello world"
End Function
Delegate Function myMethodDelegate() As String
Dim MyDelegate As New myMethodDelegate(AddressOf HelloWorld)
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Me.TextBox1.Text = MyDelegate()
End Sub
Return "Hello world"
End Function
Delegate Function myMethodDelegate() As String
Dim MyDelegate As New myMethodDelegate(AddressOf HelloWorld)
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Me.TextBox1.Text = MyDelegate()
End Sub