本文整理匯總了VB.NET中System.Action<T1,T2,T3,T4>代理的典型用法代碼示例。如果您正苦於以下問題:VB.NET Action<T1,T2,T3,T4>代理的具體用法?VB.NET Action<T1,T2,T3,T4>怎麽用?VB.NET Action<T1,T2,T3,T4>使用的例子?那麽, 這裏精選的代理代碼示例或許可以為您提供幫助。
在下文中一共展示了Action<T1,T2,T3,T4>代理的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的VB.NET代碼示例。
示例1: StringCopy
Delegate Sub StringCopy(stringArray1() As String, _
stringArray2() As String, _
indexToStart As Integer, _
numberToCopy As Integer)
Module TestDelegate
Public Sub Main()
Dim ordinals() As String = {"First", "Second", "Third", "Fourth", _
"Fifth", "Sixth", "Seventh", "Eighth", _
"Ninth", "Tenth"}
Dim copiedOrdinals(ordinals.Length - 1) As String
Dim copyOperation As StringCopy = AddressOf CopyStrings
copyOperation(ordinals, copiedOrdinals, 3, 5)
For Each ordinal As String In copiedOrdinals
Console.WriteLine(ordinal)
Next
End Sub
Private Sub CopyStrings(source() As String, target() As String, _
startPos As Integer, number As Integer)
If source.Length <> target.Length Then
Throw New IndexOutOfRangeException("The source and target arrays" & _
" must have the same number of elements.")
End If
For ctr As Integer = startPos to startpos + number - 1
target(ctr) = String.Copy(source(ctr))
Next
End Sub
End Module
示例2: TestAction4
Module TestAction4
Public Sub Main()
Dim ordinals() As String = {"First", "Second", "Third", "Fourth", _
"Fifth", "Sixth", "Seventh", "Eighth", _
"Ninth", "Tenth"}
Dim copiedOrdinals(ordinals.Length - 1) As String
Dim copyOperation As Action(Of String(), String(), Integer, Integer) = _
AddressOf CopyStrings
copyOperation(ordinals, copiedOrdinals, 3, 5)
For Each ordinal As String In copiedOrdinals
Console.WriteLine(ordinal)
Next
End Sub
Private Sub CopyStrings(source() As String, target() As String, _
startPos As Integer, number As Integer)
If source.Length <> target.Length Then
Throw New IndexOutOfRangeException("The source and target arrays" & _
" must have the same number of elements.")
End If
For ctr As Integer = startPos to startpos + number - 1
target(ctr) = String.Copy(source(ctr))
Next
End Sub
End Module
示例3: TestLambdaExpression
Public Module TestLambdaExpression
Public Sub Main()
Dim ordinals() As String = {"First", "Second", "Third", "Fourth", "Fifth", _
"Sixth", "Seventh", "Eighth", "Ninth", "Tenth"}
Dim copiedOrdinals(ordinals.Length - 1) As String
Dim copyOperation As Action(Of String(), String(), Integer, Integer) = _
Sub(s1, s2, pos, num) CopyStrings(s1, s2, pos, num)
copyOperation(ordinals, copiedOrdinals, 3, 5)
For Each ordinal As String In copiedOrdinals
If String.IsNullOrEmpty(ordinal) Then
Console.WriteLine("<None>")
Else
Console.WriteLine(ordinal)
End If
Next
End Sub
Private Function CopyStrings(source() As String, target() As String, _
startPos As Integer, number As Integer) As Integer
If source.Length <> target.Length Then
throw new IndexOutOfRangeException("The source and target arrays must have the same number of elements.")
End If
For ctr As Integer = startPos To startPos + number - 1
target(ctr) = String.Copy(source(ctr))
Next
Return number
End Function
End Module
輸出:
Fourth Fifth Sixth Seventh Eighth