- 1 public abstract class Singleton<T> where T:class,new()
- 2 {
- 3 private static readonly T instance = new T();
- 4 protected Singleton() { }
- 5
- 6 public static T GetSingleton()//获取单例
- 7 {
- 8 return instance;
- 9 }
- 10 }
- 11 public class Person : Singleton<Person> { }