将C#Lambda转换为vb.net

时间:2011-01-02 08:14:08

标签: c# vb.net lambda

将此转换为VB.NET需要帮助

   public void GetCustomers(Action<IEnumerable<Customer>> onSuccess, Action<Exception> onFail)
    {
        Manager.Customers.ExecuteAsync(op =>
              {
                  if (op.CompletedSuccessfully)
                  {
                      if (onSuccess != null) 
                          onSuccess(op.Results);
                  }
                  else
                  {
                      if (onFail != null)
                      {
                          op.MarkErrorAsHandled();
                          onFail(op.Error);
                      }
                  }
              }
           );
    }

1 个答案:

答案 0 :(得分:1)

您可以使用以下语法执行内联匿名函数/ subs:

Manager.Customers.ExecuteAsync( Sub (op)
                                  If op.CompletedSuccessfully Then
                                    ...
                                  Else
                                    ...
                                  EndIf
                                End Sub )

当你内联使用它时,事情变得非常棘手,所以当发生这种情况时,我会给本地子/函数命名:

Dim SomeFun as Action(Of OpType) = Sub (op)
                                     ...
                                   End Sub

这很有效,因为你仍然可以关闭你的词汇环境。

这一切都来自记忆 - 我家里没有VS(我尽量不去工作)。特别是,我不确定我是否在合适的位置关闭了。

MSDN Reference