
























public sealed class Singleton
{
Singleton()
{
}public static Singleton Instance
{
get
{
return Nested.instance;
}
}
class Nested
{
static Nested()
{
}internal static readonly Singleton instance = new Singleton();
}
}
泛型实现
1
public class Singleton<T> where T : new()
2
{
3
public static T Instance
4
{
5
get { return SingletonCreator.instance; }
6
}
7
8
class SingletonCreator
9
{
10
internal static readonly T instance = new T();
11
}
12
}
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。