110,533
社区成员
发帖
与我相关
我的任务
分享
struct ScreenPosition
{
private int _x, _y;
public ScreenPosition(int X, int Y)
{
this._x = rangeCheckedX(X);
this._y = rangeCheckedY(Y);
}
private static int rangeCheckedX(int x)
{
if (x < 0 || x > 1280)
{
throw new ArgumentOutOfRangeException("X");
}
return x;
}
private static int rangeCheckedY(int y)
{
if (y < 0 || y > 1024)
{
throw new ArgumentOutOfRangeException("Y");
}
return y;
}
public int X
{
get { return this._x; }
set { this._x = rangeCheckedX(value); }
}
public int Y
{
get { return this._y; }
set { this._y = rangeCheckedY(value); }
}
}
namespace AutomaticProperties
{
class Program
{
static void doWork()
{
ScreenPosition origin = new ScreenPosition(0,1000);
origin.X = origin.X + 1;
Console.WriteLine(origin.X);
}
static void Main(string[] args)
{
try
{
doWork();
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
}
}
}
这里也是,如果 static void doWork()不是static那么就出错了,静态在这里什么作用呢?