In VB.NET can you do an arbitary code block?
probably a trivially easy thing to do...
In C# you can introduce a block simply by putting in { }
eg. if you wanted to do a lambda like x => { var x="x"; var y="y"; }
so is there a way to introduce a scope / block 开发者_运维技巧in VB.NET?
Yes it's possible to introduce arbitrary blocks into VB.Net
If True Then
...
End If
In Visual Studio 2008 though you cannot do this for lambda expressions. Vb.Net only supports single expression lambdas in Visual Studio 2008. Statement lambdas were not added until Visual Studio 2010. There is no way to get that style of block functionality into an expression lambda using 2008 constructs.
Using IndentHelper()
End Using
Private Function IndentHelper() As IDisposable
Return Nothing
End Function
Also works.
Just found you can use : to chain multiple statements onto the same line, and with at the end of the line _ you can chain that across multiple lines. Not sure if that works in a lambda or not.
Still, not an arbitrary block of code
As far as I know the easiest way for an arbitrary block of code is:
With 0
...
End With
精彩评论