我有如下定义一个软件标题类:问题与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