我有如下定義一個軟件標題類:問題與LINQ查詢輸出轉換爲List <>在asp.net
public class SoftwareTitles
{
string softwareTitle;
string invoiceNumber;
public SoftwareTitles(string softwareTitle, string invoiceNumber)
{
this.softwareTitle = softwareTitle;
this.invoiceNumber = invoiceNumber;
}
public string InvoiceNumber
{
get
{
return this.invoiceNumber;
}
}
public string SoftwareTitle
{
get
{
return this.softwareTitle;
}
}
}
和我得到的軟件產品從我的LINQ查詢和發票號碼,我想用下面的代碼在清單上存儲:
List<SoftwareTitles> softwareTitlesList = new List<SoftwareTitles>();
var result = (from CustomersRecord custRecords in custRecordContainer select new { InvoiceNumber = custRecords.InvoiceNumber, SoftwareTitle = custRecords.InvoiceNumber }).ToList();
softwareTitlesList = result;
但它嚇壞了,給我這個錯誤:
Error 1 Cannot implicitly convert type 'System.Collections.Generic.List<AnonymousType#1>' to 'System.Collections.Generic.List<SoftwareTitles>'
任何人都可以幫助我嗎?
感謝預期
這與答案無關,但請注意您正在使用2個custRecords.InvoiceNumber創建對象。它看起來像你想要的:{custRecords.SoftwareTitle,custRecords.InvoiceNumber} – Blazes 2011-04-20 11:53:38