gpt4 book ai didi

c# - 系统.MissingMethodException : Method not found: 'System.String .get_DayName()'

转载 作者:行者123 更新时间:2023-11-30 15:34:03 24 4
gpt4 key购买 nike

我有以下类型:

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 属性的类型从 string 更改为 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()'。

知道为什么吗?

谢谢

最佳答案

也许你只需要重新编译?我在本地运行此代码并且运行良好。

class Program
{
static void Main(string[] args)
{
TimeBand.DoSomething();
}
}


public class TimeBand
{
public DayOfWeek DayName { get; set; }
public int customerId { get; set; }

public static void DoSomething()
{
var TimeBandList = new List<TimeBand>
{
new TimeBand()
{
DayName = DayOfWeek.Monday,
customerId = 10
},
new TimeBand()
{
DayName = DayOfWeek.Tuesday,
customerId = 11
}
};


DateTime date = DateTime.Now;
var timeBandRange = new List<TimeBand>();

timeBandRange = TimeBandList.Where
(p => p.customerId == 1
&& p.DayName == date.DayOfWeek).ToList();
}
}

关于c# - 系统.MissingMethodException : Method not found: 'System.String .get_DayName()' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16651784/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com