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 送芒果的祝福语简短
18 送给学长毕业祝福语简短