现实是什么?
不懂 ,不想懂 !!!
那不如就这样幼稚的活着,不要醒悟,饿只是傻瓜,傻傻的瓜瓜
难得糊涂啊难得糊涂,糊涂着也不要清醒,给我一段代码,足以足以,阿拜彩带不要求很多,忘记一切,快乐起来,++油,奋斗吧!
public sealed class Singleton public static Singleton Instance { get { return SingletonCreator.instance; } } class SingletonCreator { // Explicit static constructor to tell C# compiler // not to mark type as beforefieldinit static Nested() {} internal static readonly Singleton instance = new Singleton(); } } |
使用泛型,代码变成这样:
public class SingletonProvider<T> where T : new() { SingletonProvider() { } public static T Instance { get { return SingletonCreator.instance; } } class SingletonCreator { static SingletonCreator() { } internal static readonly T instance = new T(); } } |
抄过来看看,嘿嘿