zoukankan      html  css  js  c++  java
  • singletontheory.cs


      using System;

      class SingletonPattern {

      //  Singleton Pattern      Judith Bishop Dec 2006
      //  The public property protects the private constructor
        
        public sealed class Singleton {
          // Private Constructor
          Singleton() { }
          
          // Private object instantiated with private constructor
          static readonly Singleton instance = new Singleton();

          // Public static property to get the object
          public static Singleton UniqueInstance {
            get { return instance;}
          }
        }

        static void Main() {
          Singleton s1 = Singleton.UniqueInstance;
          Singleton s2 = Singleton.UniqueInstance;

          if (s1 == s2) {
            Console.WriteLine("Objects are the same instance");
          }
        }
      }
  • 相关阅读:
    优化webstorm打开项目速度
    组件 -- Button
    组件 --BreadCrumb--面包屑
    组件 -- Badge
    组件 -- Alert
    表格-table 样式
    image 样式设置
    文本和字体样式设置
    bootstrap-网格系统
    c#方法
  • 原文地址:https://www.cnblogs.com/shihao/p/2500505.html
Copyright © 2011-2022 走看看