C#静态类寿命
示例
甲static类延迟初始化上成员接入和生活应用程序域的持续时间。
void Main()
{
Console.WriteLine("Static classes are lazily initialized");
Console.WriteLine("The static constructor is only invoked when the class is first accessed");
Foo.SayHi();
Console.WriteLine("Reflecting on a type won't trigger its static .ctor");
var barType = typeof(Bar);
Console.WriteLine("However, you can manually trigger it with System.Runtime.CompilerServices.RuntimeHelpers");
RuntimeHelpers.RunClassConstructor(barType.TypeHandle);
}
//在此定义其他方法和类
public static class Foo
{
static Foo()
{
Console.WriteLine("static Foo.ctor");
}
public static void SayHi()
{
Console.WriteLine("Foo: Hi");
}
}
public static class Bar
{
static Bar()
{
Console.WriteLine("static Bar.ctor");
}
}
热门推荐
10 儿子立冬祝福语简短独特
11 对当兵的祝福语简短
12 侄儿高考试祝福语简短
13 伴郎红包祝福语朋友简短
14 媳妇生日简短祝福语朋友
15 公司年会祝福语简短最好
16 元旦感恩祝福语简短大全
17 红包祝福语简短10字
18 周六早晨祝福语简短