C#单例模式
1.单例模式
public class Car { private static Car instance = null; private static object obj = new object();//锁 private Car() { }//通过一个private禁止对Car进行实例化 public static Car Instance//只能通过此进行实例化 { get { if (instance == null) { lock (obj) { if (instance == null) { instance = new Car(); } } } return instance; } } }

浙公网安备 33010602011771号