Delegate - Function Pointer
callback .
(integer) .
,
, ,
.
,
(, , ) (main) .
callback function,
. , .
, , .
() True
,
:
' True
Delegate Function Func_Sravnyava(ByVal
x As Integer, ByVal y As Integer) As Boolean
--
:
Function
SortAscending(ByVal x As Integer, ByVal y As Integer) As Boolean
If y < x Then
SortAscending = True
End If
End Function
Function
SortDescending(ByVal x As Integer, ByVal y As Integer) As Boolean
If y > x Then
SortDescending = True
End If
End Function
. Invoke :
Sub BubbleSort(ByVal
CompareMethod As Func_Sravnyava, ByVal IntArray( ) As Integer)
Dim i, j, temp As Integer
For i = 0 To
Ubound(IntArray)
For j = i + 1 To
Ubound(IntArray)
If
CompareMethod.Invoke(IntArray(i), IntArray(j)) Then
Temp = IntArray(j)
IntArray(j) = IntArray(i)
IntArray(i) = Temp
End If
Next j
Next i
End Sub
:
Protected Sub
Button1_Click(ByVal sender As Object, _
ByVal e As
System.EventArgs)
Dim i As Integer
Dim iArray() As Integer =
New Integer( ) {6, 2, 4, 9}
BubbleSort(AddressOf
SortAscending, iArray)
For i = 0 To 3
Debug.WriteLine(CStr(iArray(i)))
Next
BubbleSort(AddressOf
SortDescending, iArray)
For i = 0 To 3
Debug.WriteLine(CStr(iArray(i)))
Next
End Sub
: 2 4 6 9 9 6 4 2
-
(event) , .
(, ),
(,
), (
). , , (raised), (fired). (source).
, , .
, .
, . , Microsoft (sender).
(event argument), ,
.
,
(Shift, Alt, Ctrl).

69 DelegateFuncPointer -
Output Debug.
. Event handler ( ) . event handler
(binding)
.