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.
精彩评论