我有以下类型:
public class TimeBand
{
public string DayName { get; set; }
public int customerId { get; set; }
}
我正在创建一个包含 TimeBands 的列表:
var TimeBandList = new List<TimeBand>
{
new TimeBand()
{
DayName = DayOfWeek.Monday.ToString(),
customerId = 10
},
new TimeBand()
{
DayName = DayOfWeek.Tuesday.ToString(),
customerId = 11
}
.....
};
我正在使用以下内容将 TimeBands 加载到另一个列表中:
var timeBandRange = new List<TimeBand>();
timeBandRange = TimeBandList.Where
(p => p.customerId == newCustomerId
&& p.DayName == date.DayOfWeek.ToString()).ToList();
这工作正常,但在 TimeBand 类中,我决定将DayName属性的类型从字符串更改为DayOfWeek ,因此代码变成了这样:
public class TimeBand
{
public DayOfWeek DayName { get; set; }
public int customerId { get; set; }
}
var TimeBandList = new List<TimeBand>
{
new TimeBand()
{
DayName = DayOfWeek.Monday,
customerId = 10
},
new TimeBand()
{
DayName = DayOfWeek.Tuesday,
customerId = 11
}
.....
};
DateTime date = IndDate;
var timeBandRange = new List<TimeBand>();
timeBandRange = TimeBandList.Where
(p => p.customerId == parameter.customerId
&& p.DayName == date.DayOfWeek).ToList();
这个新代码现在在 TimeBandList.Where行上失败并给出以下错误:System.MissingMethodException:找不到方法:'System.String TimeBand.get_DayName()'。
知道为什么吗?
谢谢