2011-07-26 106 views
1

如何將以下代碼轉換爲vb.net?如何將C#Linq轉換爲Vb.net

我不能轉換​​

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

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

    ObjectDumper.Write(orderCounts); 
} 

回答

3

這是C#的匿名類。 VB也支持這一點。請參閱this示例。

關於在VB中使用LINQ的基本信息:試試這個resource

4

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)