C# 公共setter方法将不会更新
所以我在这个问题上挠头已经有一段时间了,我想不出来。我完成了一些调试步骤以查看它挂起的位置,VisualStudio不会给我任何信息。基本上,我有一个带有数组的类,它跟踪数组和当前图像的当前索引 然而,当我调试(或不调试)时,无论“index”的值是什么,“currentLocation”都不会得到更新。我似乎不知道问题出在哪里。有什么建议吗C# 公共setter方法将不会更新,c#,C#,所以我在这个问题上挠头已经有一段时间了,我想不出来。我完成了一些调试步骤以查看它挂起的位置,VisualStudio不会给我任何信息。基本上,我有一个带有数组的类,它跟踪数组和当前图像的当前索引 然而,当我调试(或不调试)时,无论“index”的值是什么,“currentLocation”都不会得到更新。我似乎不知道问题出在哪里。有什么建议吗 public class TestClass : INotifyPropertyChanged { //... public void
public class TestClass : INotifyPropertyChanged
{
//...
public void GoTo(int index)
{
if (index == currentLocation)
return;
else if (index >= data.Length)
this.currentLocation = data.Length - 1;
else if (index <= 0)
this.currentLocation = 0;
else
this.currentLocation = index;
//this is where the debugging drops off
}
//doesn't matter if I initialize the value or not
//private int _currentLocation = 0;
private int _currentLocation;
public int currentLocation
{
get { return _currentLocation; }
set
{
//never hits this line
this.SetProperty(ref this._currentLocation, value);
//more work
}
}
//...
}
公共类TestClass:INotifyPropertyChanged
{
//...
公共无效转到(整数索引)
{
如果(索引==当前位置)
返回;
else if(索引>=data.Length)
this.currentLocation=data.Length-1;
否则,如果(索引根据您在评论中的回答,我们看到您在setter中没有任何断点,但尝试使用F11(单步执行)。在禁用相应的调试器设置之前,它不会工作。打开工具->选项->调试。查找选项“跳过属性和运算符”(默认情况下应启用)如果方便的话,可以禁用它。或者在setter中设置断点。您不需要第一个if
。放下它,看看会发生什么。实际上,我使用if语句来确保如果新索引与当前位置相同,我不会“更新”值。但是,我尝试删除if语句(和return语句)不管怎样,它仍然没有改变任何东西。你能澄清一下“从不点击这一行”吗?你在setter中有断点吗?这是一种标准的调试器行为。尝试在setter中设置断点,但在setter中设置断点,调试器跳过道具get和set。