【问题标题】:How to do this in VB 2010 (C# to VB conversion)如何在 VB 2010 中执行此操作(C# 到 VB 转换)
【发布时间】:2010-05-19 21:19:18
【问题描述】:

我希望将以下内容翻译成 VB 2010(使用高级语法)


_domainContext.SubmitChanges(
     submitOperation =>
     {
        _domainContext.Load<Customer>(
             _domainContext.GetCustomersQuery(),
              LoadBehavior.RefreshCurrent,
              loadOperation =>
              {
                 var results = _domainContext.Customers.Where(
                         entity => !loadOperation.Entities.Contains(entity)).ToList();

                 results.ForEach( enitity => _domainContext.Customers.Detach(entity));
              }, null);
      }, null);

我设法通过其他方式获得上述信息(但不使用匿名方法)。我希望看到 VB 2010 中可用的所有高级语法都应用于上述内容。

谁能帮我解决这个问题?

谢谢

【问题讨论】:

标签: vb.net anonymous-methods c#-to-vb.net


【解决方案1】:
_domainContext.SubmitChanges(
    Sub(submitOperation)
        _domainContext.Load<Customer>(
            _domainContext.GetCustomersQuery(),
            LoadBehavior.RefreshCurrent,
            Sub(loadOperation)
                Dim results = _domainContnext.Customers.Where(
                                Function(entity) Not loadOperation.Entities.Contains(entity)) _
                                .ToList();
                results.ForEach(Sub(entity) _domainContext.Customers.Detach(entity))
            End Sub,
            Nothing)
    End Sub, Nothing)

我显然无法将其放入编译器中,但这应该会让您朝着正确的方向前进。基本上,在 C# 中看到=&gt; 的任何地方,都将替换为内联的SubFunction,具体取决于是否需要返回值。如果 C# lambda 中有大括号,您将在 VB 中得到一个多行子/函数。请注意,您只能在 VB2010 中执行此操作,因为 VB08 不支持 Sub lambda 或多行 Function lambda。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2014-12-24
    • 2016-04-28
    • 2011-01-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多