VB.Net/Generics/Generic Delegate — различия между версиями
Admin (обсуждение | вклад) м (1 версия) |
Admin (обсуждение | вклад) м (1 версия) |
(нет различий)
|
Текущая версия на 12:42, 26 мая 2010
Generic delegate can point to any method taking a single argument (specified at the time of creation)
Option Explicit On
Option Strict On
Public Delegate Sub MyGenericDelegate(Of T)(ByVal arg As T)
Public Delegate Sub MyDelegate(ByVal arg As Object)
Module Program
Sub Main()
Dim d As New MyGenericDelegate(Of Integer)(AddressOf IntegerTarget)
d(100)
Dim d2 As New MyGenericDelegate(Of String)(AddressOf StringTarget)
d2("Cool!")
End Sub
Public Sub IntegerTarget(ByVal arg As Integer)
Console.WriteLine("You passed me a {0} with the value of {1}", arg.GetType().Name, arg)
End Sub
Public Sub StringTarget(ByVal arg As String)
Console.WriteLine("You passed me a {0} with the value of {1}", arg.GetType().Name, arg)
End Sub
End Module