我发现 this answer在 VS2010 实际发布之前被问及回答。
他们说
VB9 has only single-line anonymous functions. We're adding full statement and multi-line lambdas in VB10.
但我尝试添加此代码
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 项目,但无法编译。
你现在是否真的实现了这个功能,我做错了什么?
最佳答案
我相信您只是缺少“结束功能”行。尝试这个:
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)
End Function)
关于vb.net - VB.NET 和 Visual Studio 2010 是否支持多行匿名方法?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3864836/