再来一个。。。单件模式。
- class Program
- {
- static void Main(string[] args)
- {
- SingletonClass c1 = SingletonClass.Instance;
- c1.Property1 = "first";
- Console.WriteLine(c1.Property1);
- SingletonClass c2 = SingletonClass.Instance;
- c2.Property1 = "second";
- Console.WriteLine(c1.Property1);
- Console.Read();
- }
- }
- public class SingletonClass
- {
- private SingletonClass() { }
- private static SingletonClass instance = null;
- public static SingletonClass Instance
- {
- get
- {
- if (instance == null)
- {
- instance = new SingletonClass();
- }
- return SingletonClass.instance;
- }
- }
- public string Property1 { get; set; }
- }