单例模式
我们以前写过了很多中单例模式,确实都能实现我们想要的功能,但是单例模式最好的一种我觉得还是下列代码所示:
public sealed class Singleton { Singleton() { } public static Singleton Instance() { { return Nested.instance; } } class Nested { static Nested() { } internal static readonly Singleton instance = new Singleton(); } } }

浙公网安备 33010602011771号