【发布时间】:2011-08-24 13:41:08
【问题描述】:
我只是做了一个小实验:
public abstract class MyClass
{
private static int myInt = 0;
public static int Foo()
{
return myInt;
}
public static int Foo(int n)
{
myInt = n;
return bar();
}
private static int bar()
{
return myInt;
}
}
然后我跑了:
MessageBox.Show(MyClass.Foo().ToString());
MessageBox.Show(MyClass.Foo(3).ToString());
MessageBox.Show(MyClass.Foo().ToString());
MessageBox.Show(MyClass.Foo(10).ToString());
MessageBox.Show(MyClass.Foo().ToString());
我预期的结果是 0、3、0、10、0。
令我惊讶的是,我得到了 0、3、3、10、10。
这些变化会持续多久?程序执行的持续时间?函数调用静态方法的持续时间?
【问题讨论】:
标签: c# static-methods static-members