为什么匿名Action可以在C#中的一行中调用而不是VB?

djv*_*djv 3 .net c# vb.net

在C#中

(new Action(() => MessageBox.Show("Hello"))).BeginInvoke(null, null);
Run Code Online (Sandbox Code Playgroud)

在VB中,已翻译的代码无法编译

(New Action(Sub() MessageBox.Show("Hello"))).BeginInvoke(nothing, nothing)
Run Code Online (Sandbox Code Playgroud)

但是在VB中我可以将BeginInvoke的结果设置为隐式变量a并且它将运行(感谢@Ric在另一篇文章中提出此建议)

Dim a = (New Action(Sub() MessageBox.Show("Hello"))).BeginInvoke(Nothing, Nothing)
Run Code Online (Sandbox Code Playgroud)

但是现在我想知道为什么VB在这种情况下需要在左侧设置某些东西,而C#则没有.

J. *_*een 5

VB.NET只需要一个标识符.您不能直接调用子或其他成员.但是,您可以使用Call.

当被调用表达式不以标识符开头时,通常使用Call关键字.建议不要将Call关键字用于其他用途.

http://msdn.microsoft.com/en-us/library/sxz296wz(v=vs.110).aspx

Call (New Action(Sub() MessageBox.Show("Hello"))).BeginInvoke(nothing, nothing)
Run Code Online (Sandbox Code Playgroud)