par*_*mar 118
public class Application
{
static int attribute;
static Application()
{
attribute = 5;
} // removed
}
Run Code Online (Sandbox Code Playgroud)
您可以使用C#等效的静态构造函数.请不要将它与常规构造函数混淆.常规构造函数static前面没有修饰符.
我假设你//... rest of the code需要也跑一次.如果您没有这样的代码,您可以简单地执行此操作.
public class Application
{
static int attribute = 5;
}
Run Code Online (Sandbox Code Playgroud)
Aja*_*jai 12
你可以像这样写一个静态构造函数块,
static Application(){
attribute=5;
}
Run Code Online (Sandbox Code Playgroud)
这是我能想到的.
| 归档时间: |
|
| 查看次数: |
39687 次 |
| 最近记录: |