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

      using System;

      class SingletonPattern {

        //  Singleton Pattern      Judith Bishop Nov 2007
        //  The public property protects the private constructor
          
        public class Singleton {
          // Private constructor
          Singleton () { }
          
          // Nested class for lazy instantiation
          class SingletonCreator {
            static SingletonCreator () {}
            // Private object instantiated with private constructor
            internal static readonly
            Singleton uniqueInstance = new Singleton();
          }

          // Public static property to get the object
          public static Singleton UniqueInstance {
            get {return SingletonCreator.uniqueInstance;}
          }
        }

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

          if (s1 == s2) {
            Console.WriteLine("Objects are the same instance");
          }
        }
      }
  • 相关阅读:
    ElasticSearch调优问题
    Ceph源码解析:概念
    Ceph神坑系列
    Mac下VirtualBox共享文件夹设置
    API教程
    设计师最常用网站汇总
    从码农到大神,有多少经验值得借鉴?
    登录注册 页面
    NET面试题 (四)
    Sqlserver面试题
  • 原文地址:https://www.cnblogs.com/shihao/p/2500510.html
Copyright © 2011-2022 走看看