提供对延迟初始化的支持。
//不会执行new Test()
Lazy<Test> lazyTest = new Lazy<Test>(()=>new Test());
//当调用lazyTest.Value时,才会创建Test对象
lazyTest.Value.Fun();
using System;
using System.Threading;
public class SingletonLazy
{
//延迟创建单例实例
private static Lazy<SingletonLazy> _instance = new Lazy<SingletonLazy>(LazyThreadSafetyMode.ExecutionAndPublication);
public static SingletonLazy GetInstance()
{
return _instance.Value;
}
}