110,571
社区成员
发帖
与我相关
我的任务
分享
public static class StaticClass<T>
{
public static T Value = default(T);
}
//测试
public static void Test()
{
Console.WriteLine(StaticClass<int>.Value);
StaticClass<int>.Value = 100;
GC.Collect();
GC.WaitForFullGCComplete();
Console.WriteLine(StaticClass<int>.Value);
}
public static class StaticClass<T> where T :new()
{
private static T instance;
public static T Instance
{
get
{
//Lazy initialize
if (instance == null)
{
instance = new T();
}
return instance;
}
}
}