If you are using Visual Studio 2008 (VB.NET 9), there is a restriction in VB.NET that requires lambda expressions to return a value, so you cannot use Sub . This has changed in VB.NET 10, so in this environment your code should work properly.
The problem is that on the one hand you need to make your lambda expression in Function , not Sub , and on the other hand Console.WriteLine has no return value. The solution is to wrap this in a function that calls Console.WriteLine and returns a value:
Private Function ConsoleWriteLine(ByVal text As String) As String Console.WriteLine(text) Return text End Function
Then you can use this function in your lambda expression:
Dim DoIt As Action(Of String) DoIt = Function(s) ConsoleWriteLine(s)
source share