本文整理汇总了VB.NET中System.Action<T>代理的典型用法代码示例。如果您正苦于以下问题:VB.NET Action<T>代理的具体用法?VB.NET Action<T>怎么用?VB.NET Action<T>使用的例子?那么恭喜您, 这里精选的代理代码示例或许可以为您提供帮助。
在下文中一共展示了Action<T>代理的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的VB.NET代码示例。
示例1: Main
' 导入命名空间
Imports System.Collections.Generic
Class Program
Shared Sub Main()
Dim names As New List(Of String)
names.Add("Bruce")
names.Add("Alfred")
names.Add("Tim")
names.Add("Richard")
' Display the contents of the list using the Print method.
names.ForEach(AddressOf Print)
End Sub
Shared Sub Print(ByVal s As String)
Console.WriteLine(s)
End Sub
End Class
' This code will produce output similar to the following:
' Bruce
' Alfred
' Tim
' Richard
示例2: DisplayMessage
Delegate Sub DisplayMessage(message As String)
Module TestCustomDelegate
Public Sub Main
Dim messageTarget As DisplayMessage
If Environment.GetCommandLineArgs().Length > 1 Then
messageTarget = AddressOf ShowWindowsMessage
Else
messageTarget = AddressOf Console.WriteLine
End If
messageTarget("Hello, World!")
End Sub
Private Sub ShowWindowsMessage(message As String)
MsgBox(message)
End Sub
End Module
示例3: TestAction1
Module TestAction1
Public Sub Main
Dim messageTarget As Action(Of String)
If Environment.GetCommandLineArgs().Length > 1 Then
messageTarget = AddressOf ShowWindowsMessage
Else
messageTarget = AddressOf Console.WriteLine
End If
messageTarget("Hello, World!")
End Sub
Private Sub ShowWindowsMessage(message As String)
MsgBox(message)
End Sub
End Module
示例4: TestLambdaExpression
' 导入命名空间
Imports System.Windows.Forms
Public Module TestLambdaExpression
Public Sub Main()
Dim messageTarget As Action(Of String)
If Environment.GetCommandLineArgs().Length > 1 Then
messageTarget = Sub(s) ShowWindowsMessage(s)
Else
messageTarget = Sub(s) ShowConsoleMessage(s)
End If
messageTarget("Hello, World!")
End Sub
Private Function ShowWindowsMessage(message As String) As Integer
Return MessageBox.Show(message)
End Function
Private Function ShowConsoleMessage(message As String) As Integer
Console.WriteLine(message)
Return 0
End Function
End Module