本文整理匯總了VB.NET中System.Action<T1,T2>代理的典型用法代碼示例。如果您正苦於以下問題:VB.NET Action<T1,T2>代理的具體用法?VB.NET Action<T1,T2>怎麽用?VB.NET Action<T1,T2>使用的例子?那麽, 這裏精選的代理代碼示例或許可以為您提供幫助。
在下文中一共展示了Action<T1,T2>代理的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的VB.NET代碼示例。
示例1: ConcatStrings
' 導入命名空間
Imports System.IO
Delegate Sub ConcatStrings(string1 As String, string2 As String)
Module TestDelegate
Public Sub Main()
Dim message1 As String = "The first line of a message."
Dim message2 As String = "The second line of a message."
Dim concat As ConcatStrings
If Environment.GetCommandLineArgs().Length > 1 Then
concat = AddressOf WriteToFile
Else
concat = AddressOf WriteToConsole
End If
concat(message1, message2)
End Sub
Private Sub WriteToConsole(string1 As String, string2 As String)
Console.WriteLine("{0}{1}{2}", string1, vbCrLf, string2)
End Sub
Private Sub WriteToFile(string1 As String, string2 As String)
Dim writer As StreamWriter = Nothing
Try
writer = New StreamWriter(Environment.GetCommandLineArgs(1), False)
writer.WriteLine("{0}{1}{2}", string1, vbCrLf, string2)
Catch
Console.WriteLine("File write operation failed...")
Finally
If writer IsNot Nothing Then writer.Close
End Try
End Sub
End Module
示例2: TestAction2
' 導入命名空間
Imports System.IO
Module TestAction2
Public Sub Main()
Dim message1 As String = "The first line of a message."
Dim message2 As String = "The second line of a message."
Dim concat As Action(Of String, String)
If Environment.GetCommandLineArgs().Length > 1 Then
concat = AddressOf WriteToFile
Else
concat = AddressOf WriteToConsole
End If
concat(message1, message2)
End Sub
Private Sub WriteToConsole(string1 As String, string2 As String)
Console.WriteLine("{0}{1}{2}", string1, vbCrLf, string2)
End Sub
Private Sub WriteToFile(string1 As String, string2 As String)
Dim writer As StreamWriter = Nothing
Try
writer = New StreamWriter(Environment.GetCommandLineArgs(1), False)
writer.WriteLine("{0}{1}{2}", string1, vbCrLf, string2)
Catch
Console.WriteLine("File write operation failed...")
Finally
If writer IsNot Nothing Then writer.Close
End Try
End Sub
End Module
示例3: TestLambdaExpression
' 導入命名空間
Imports System.IO
Public Module TestLambdaExpression
Public Sub Main()
Dim message1 As String = "The first line of a message."
Dim message2 As String = "The second line of a message."
Dim concat As Action(Of String, String)
If Environment.GetCommandLineArgs().Length > 1 Then
concat = Sub(s1, s2) WriteToFile(s1, s2)
Else
concat = Sub(s1, s2) WriteToConsole(s1, s2)
End If
concat(message1, message2)
End Sub
Private Function WriteToConsole(string1 As String, string2 As String) As Integer
Dim message As String = String.Format("{0}{1}{2}", string1, vbCrLf, string2)
Console.WriteLine(message)
Return message.Length
End Function
Private Function WriteToFile(string1 As String, string2 As String) As Integer
Dim writer As StreamWriter = Nothing
Dim message As String = String.Format("{0}{1}{2}", string1, vbCrLf, string2)
Dim charsWritten As Integer
Try
writer = New StreamWriter(Environment.GetCommandLineArgs()(1), False)
writer.WriteLine(message)
Catch
Console.WriteLine("File write operation failed...")
Finally
If writer IsNot Nothing Then
writer.Close()
charsWritten = message.Length
Else
charsWritten = 0
End If
End Try
Return charsWritten
End Function
End Module