简体   繁体   English

如何将C#Linq转换为Vb.net

[英]How can I convert C# Linq to Vb.net

How can I convert below code to vb.net? 如何将以下代码转换为vb.net?

I can not convert select new { c.CustomerID, OrderCount = c.Orders.Count() }; 我无法转换select new { c.CustomerID, OrderCount = c.Orders.Count() };

public void Linq76()
{
    List<Customer> customers = GetCustomerList();

    var orderCounts =
        from c in customers
        select new { c.CustomerID, OrderCount = c.Orders.Count() };

    ObjectDumper.Write(orderCounts);
}

With this tool . 有了这个工具

Public Sub Linq76()
    Dim customers As List(Of Customer) = GetCustomerList()

    Dim orderCounts = From c In customers New With { _
        c.CustomerID, _
        Key .OrderCount = c.Orders.Count() _
    }

    ObjectDumper.Write(orderCounts)
End Sub

MSDN:Anonymous Types (Visual Basic) MSDN:匿名类型(Visual Basic)

That's C#'s anonymous classes. 那是C#的匿名类。 VB has support for that too. VB也对此提供支持。 See this example. 这个例子。

For basic info on using LINQ in VB: try this resource . 有关在VB中使用LINQ的基本信息,请尝试使用此资源

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM