我是c#的新手,在將其分配給查詢後嘗試訪問IList時出現問題。這裏是我的代碼:將查詢從IList轉換爲對象
System.Collections.IList Invoices =
(from p in entities.InvoiceCards
where (p.CustomerCard.ID == CustomerID)
select new
{
InvoiceID = p.ID,
InvoiceDatetime = p.DateTime,
InvoiceTotal = (decimal) p.InvoiceTotal,
}).ToList();
// update the grid
invoiceCardDataGridView.DataSource = Invoices;
-----------這裏編譯器抱怨對象C?如何在不執行查詢的情況下訪問IList中的對象?我需要使用IList作爲數據源。什麼是更好的方法?請包括代碼
foreach (var c in Invoices)
InvoiceTotal += (decimal)c.InvoiceTotal;
的可能重複[訪問C#匿名類型的對象(http://stackoverflow.com/questions/713521/accessing-c-sharp-anonymous-type-objects) – nawfal 2014-06-28 07:55:18