vb.net lambda语法特点:
由于存在上述限制,并且由于 lambda 表达式的使用方式,lambda 表达式通常简短而不复杂。
示例:
Private Sub Button3_Click(ByVal sender As System.Object,ByVal e As System.EventArgs) Handles Button3.Click
Dim ArrInt As New List(Of Integer)
For i As Integer = 1 To 20
ArrInt.Add(i)
Next
Dim EvenOne As New List(Of Integer)
EvenOne = ArrInt.FindAll(New Predicate(Of Integer)(AddressOf EvenGetter))
For Each m In EvenOne
Console.WriteLine(m)
Next
Dim EvenTwo As New List(Of Integer)
EvenTwo = ArrInt.FindAll(Function(p As Integer) p Mod 2 = 0)
For Each m In EvenTwo
Console.WriteLine(m)
Next
End Sub
Public Function EvenGetter(ByVal p As Integer) As Boolean Return p Mod 2 = 0 End Function
原文链接:https://www.f2er.com/vb/260848.html