【发布时间】:2018-03-28 05:07:50
【问题描述】:
这是我的课程代码
public class WMBillable
{
public string Month { get; set; }
public int Year { get; set; }
public int MonthNum { get; set; }
}
这是我的方法,其中包含:
foreach (var dt in lDistinctDate)
{
WMNB = new WMBillable();
DateTime Cur = new DateTime();
Cur = Convert.ToDateTime(dt.InvoiceDate);
WMNB.MonthNum = Convert.ToInt32(Cur.Month);
WMNB.Year = Convert.ToInt32(Cur.Year);
lstWMB.Add(WMNB);
}
var CurrentMonthYear = lstWMB.OrderByDescending(item => item.Year).ThenBy(x => x.Month).FirstOrDefault();
List<WMBillable> lstQu = CurrentMonthYear.ToList();
在这行代码List<WMBillable> lstQu = CurrentMonthYear.ToList() 中,我无法将提取的 linq 查询转换为列表。我收到类似“WMBillable 不包含 ToList() 的定义并且没有扩展方法 toList 接受 WMBillable 类型的第一个参数”之类的错误。
如果我进行自动更正,它会像这样在我的模型类中生成内部列表
public class WMBillable
{
public string Month { get; set; }
public int Year { get; set; }
public int MonthNum { get; set; }
internal List<WMBillable> ToList()
{
throw new NotImplementedException();
}
}
我不知道要纠正这个..请帮助这个 dot net 初学者。
【问题讨论】:
标签: c# .net linq linq-to-sql