开发者

How can I convert C# Linq to Vb.net

How can I convert below code to vb.net?开发者_运维知识库

I can not convert 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)


That's C#'s anonymous classes. VB has support for that too. See this example.

For basic info on using LINQ in VB: try this resource.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜