从我可以在google上找到,VB.NET只有一个语句的lambdas,而不是多语句的匿名函数.然而,我读过的所有文章都在谈论旧版本的VB.NET,我找不到比vs2008 beta 1或2更新的内容.
所以问题:我如何在VB.NET中这样做?
C#代码:
private void HandleErrors( Action codeBlock ){ try{ codeBlock(); }catch(Exception e){ //log exception,etc } } HandleErrors(() => { var x = foo(); x.DoStuff(); etc });
它在VB10中:
原文链接:https://www.f2er.com/vb/255680.htmlDim food = New With { .ID = 1,.Name = "Carrot",.Type = ( Function(name As String) If String.IsNullOrEmpty(name) Then Return String.Empty Select Case name.ToLower() Case "apple","tomato": Return "Fruit" Case "potato": Return "Vegetable" End Select Return "Meat" End Function )(.Name) } Dim type = food.Type