我读了这个答案:https ://stackoverflow.com/a/9928643/16241
但我显然不明白,因为我无法弄清楚为什么我的方法不纯。(有问题的方法是ToExactLocation()
)。
public struct ScreenLocation
{
public ScreenLocation(int x, int y):this()
{
X = x;
Y = y;
}
public int X { get; set; }
public int Y { get; set; }
public ExactLocation ToExactLocation()
{
return new ExactLocation {X = this.X, Y = this.Y};
}
// Other stuff
}
如果您需要它,这里是确切的位置结构:
public struct ExactLocation
{
public double X { get; set; }
public double Y { get; set; }
// Various Operator Overloads, but no constructor
}
这就是我所说的:
someScreenLocation = MethodThatGivesAScreenLocation();
if (DestinationLocation == someScreenLocation.ToExactLocation())
{
// Do stuff
}
当我这样做时,ReSharper 将其标记为"Impure Method is called for readonly field of value type."
为什么这么说?我该怎么做才能让它消失?