VB.NET 和 Visual Studio 2010 是否支持多行匿名方法?
我发现这个答案在VS2010实际发布之前就被问到并得到了回答。
他们说
VB9只有单行匿名 功能。我们正在添加完整的声明 以及 VB10 中的多行 lambda。
但我尝试将此代码添加
Dim test2 = Function(t1 As T, t2 As T) (
Dim val1 As IComparable = DirectCast(prop.GetValue(t1), IComparable)
Dim val2 As IComparable = DirectCast(prop.GetValue(t2), IComparable)
Return val1.CompareTo(val2)
)
到 Visual Studio 2010 中的 .NET Framework 4.0 项目中,但它无法编译。
你现在知道这个功能是否真的实现了以及我做错了什么吗?
I found that this answer was asked and answered before VS2010 was actually released.
They say that
VB9 has only single-line anonymous
functions. We're adding full statement
and multi-line lambdas in VB10.
But I tried to add this code
Dim test2 = Function(t1 As T, t2 As T) (
Dim val1 As IComparable = DirectCast(prop.GetValue(t1), IComparable)
Dim val2 As IComparable = DirectCast(prop.GetValue(t2), IComparable)
Return val1.CompareTo(val2)
)
to a .NET Framework 4.0 project in Visual Studio 2010 and it does not compile.
Do you now if this feature is really implemented and what I am doing wrong?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我相信您只是错过了“结束功能”行。试试这个:
I believe you are only missing your 'End Function' line. Try this:
您缺少
End Function
并且您试图将函数体括在括号中,这是错误的。这应该有效:此功能记录在此处:
You are missing
End Function
and you are trying to enclose the function body in parenthesis, which is wrong. This should work:This feature is documented here:
以下是您可能会觉得有用的东西。请注意如何立即调用声明的方法。
Here is something you might find useful. Note how the method declared is instantly invoked.