如果我尝试使用相同的参数声明静态和非静态方法,编译器将返回错误:类型“Test”已经定义了一个名为“Load”的具有相同参数类型的成员。
class Test
{
int i = 0;
public int I
{
get { return i; }
set { i = value; }
}
public bool Load(int newValue)
{
i = newValue;
return true;
}
public static Test Load(int newValue)
{
Test t = new Test();
t.I = newValue;
return t;
}
据我所知,这两种方法不能混合使用,在对象上调用非静态方法,而在类上调用静态方法,那么为什么编译器不允许这样的事情,有没有办法做类似的事情?