Dim doubleIt As Func(Of Integer, Integer) = _ Function(x As Integer) x * 2
Dim f0 As Func(Of Boolean) Dim f1 As Func(Of Integer, Boolean) Dim f4 As Func(Of Integer, Integer, Integer, Integer, Boolean)
Dim doubleIt As Func(Of Integer, Integer) = _ Function(x As Integer) x * 2 Dim z = doubleIt(20)
Dim mult As Func(Of Integer, Func(Of Integer, Integer)) = _ Function(x As Integer) Function(y As Integer) x * y
Dim mult As Func(Of Integer, Func(Of Integer, Integer)) = _ Function(x As Integer) _ Function(y As Integer) x * y
Dim mult_10 = mult(10) Dim r = mult_10(4)
Delegate Function ShouldProcess(Of T)(element As T) As Boolean Sub ProcessList(Of T)( _ elements As List(Of T), shouldProcess As ShouldProcess(Of T)) For Each elem in elements If shouldProcess(elem) Then ' Do some processing here End If Next End Sub
Class Person Public age As Integer End Class Function _PrivateShouldProcess(person As Person) As Boolean Return person.age > 50 End Function Sub DoIt() Dim list As New List(Of Person) ' Obtain list of Person from a database, for example ProcessList(list, AddressOf _PrivateShouldProcess) End Sub
Class Person Public age As Integer End Class Sub DoIt() Dim list As New List(Of Person) ' Obtain list of Person from a database, for example ProcessList(list, Function(person As Person) person.age > 50) End Sub
Dim q = From p In Process.GetProcesses() _ Where p.PriorityClass = ProcessPriorityClass.High _ Select p
Dim q = Process.GetProcesses().Where( _ Function(p) p.PriorityClass = ProcessPriorityClass.High)
Dim lambda As Func(Of Integer, Integer) = Function(x) x * x
Delegate Function ShouldProcess(Of T)(element As T) As Boolean Sub ProcessList(Of T)( _ elements As List(Of T), shouldProcess As ShouldProcess(Of T)) ' Method body removed for brevity End Sub
Sub DoIt() Dim list As New List(Of A) ' fill or obtain elements in list ProcessList(list, Function(a) a.x > 50) End Sub
Dim lambda = Function(x As Integer) x * x
Class Motorcycle Public color As String Public CC As Integer Public weight As Integer End Class Sub PrintReport(motorcycle As New Motorcycle) If motorcycle.color = "Red" And motorcycle.CC = 600 And _ motorcycle.weight > 300 And motorcycle.weight < 400 Then ' do something here End If ' do something here If motorcycle m.color = "Red" And motorcycle.CC = 600 And _ motorcycle.weight > 300 And motorcycle.weight < 400 Then ' do something here End If End Sub
Sub PrintReport(motorcycle As New Motorcycle) Dim check = Function(m As Motorcycle) m.color = "Red" And _ m.CC = 600 And _ m.weight > 300 And _ m.weight < 400 If check(motorcycle) Then ' do something here End If ' do something here If check(motorcycle) Then ' do something here End If End Sub
Dim lambda = Function(x) x * x
Dim a = lambda(10) Dim b = lambda(CDec(10)) Dim c = lambda("This will throw an exception because " & _ "strings don't support the * operator")
Sub TestLambda() Dim doubleIt As Func(Of Integer, Integer) = _ Function(x As Integer) x * 2 Console.WriteLine(doubleIt(10)) End Sub
Function $GeneratedFunction$(x As Integer) As Integer Return x * 2 End Sub Sub TestLambda() Dim doubleIt As Func(Of Integer, Integer) = _ AddressOf $GeneratedFunction$ Console.WriteLine(doubleIt(10)) End Sub
Dim y As Integer = 10 Dim addTen As Func(Of Integer, Integer) = Function(ByVal x) x + y
Function MakeLambda() As Func(Of Integer, Integer) Dim y As Integer = 10 Dim addTen As Func(Of Integer, Integer) = Function(ByVal x) x + y Return addTen End Function Sub UseLambda() Dim addTen = MakeLambda() Console.WriteLine(addTen(5)) End Sub
Function MakeLambda() As Func(Of Integer, Integer) Dim y As Integer = 10 Dim addTen As Func(Of Integer, Integer) = Function(ByVal x) x + y Return Lambda End Function
Public Class _Closure$__1 Public y As Integer Public Function _Lambda$__1(ByVal x As Integer) As Integer Return x + Me.y End Function End Class
Function MakeLambda() As Func(Of Integer, Integer) Dim Closure As New _Closure$__1 Closure.y = 10 Return AddressOf Closure._Lambda$__1 End Function
Sub Test() Dim y As Integer = 10 Dim Lambda As Func(Of Integer, Integer) = Function(ByVal x) x + y y = 20 Console.WriteLine(Lambda(5)) End Sub
Sub Test() Dim Closure As New $CLOSURE_Compiler_Generated_Name$ Closure.y = 10 Dim Lambda = AddressOf Closure.Lambda_1 Closure.y = 20 Console.WriteLine(Lambda(5)) End Function
Sub Test() For I = 1 To 5 StartThread(Function() I + 10) Next End Function
Sub Test() For I = 1 To 5 Dim x = I StartThread(Function() x + 10) Next End Function
Dim x = If(condition, 10, 20)
Dim x = Function(c As Customer) _ If(c.Age >= 18, c.Address, c.Parent.Address)