开发环境 Windows10+VS2019+.Net Core3.1
参考了:https://www.cnblogs.com/xuzeyu/p/9400815.html
------------------------------------------------分割线---------------------------------------------------
必须精通的设计模式
抽象工厂模式
单例模式
装饰者模式
观察者模式
适配器模式
------------------------------------------------分割线 2020-8-11 17:04:34 ---------------------------------------------------
单例模式
/// <summary> /// 饿汉模式 /// </summary> public class Singleton { private static Singleton instance = new Singleton(); private Singleton() { } public static Singleton getInstance() { return instance; } } /// <summary> /// 懒汉模式 /// </summary> public class SingletonLock { private static SingletonLock instance; private static readonly object lockObject = new object(); public static SingletonLock getInstance() { lock (lockObject) { if (instance == null) { instance = new SingletonLock(); } } return instance; } }