zoukankan      html  css  js  c++  java
  • 三种单例模式demo

     1

    using System;

    public class Singleton
    {
       private static Singleton instance;

       private Singleton() {}

       public static Singleton Instance
       {
          get 
          {
             if (instance == null)
             {
                instance = new Singleton();
             }
             return instance;
          }
       }
    }

    2


    public sealed class Singleton
    {
       private static readonly Singleton instance = new Singleton();
       
       private Singleton(){}

       public static Singleton Instance
       {
          get 
          {
             return instance; 
          }
       }
    }

    3

    using System;

    public sealed class Singleton
    {
       private static volatile Singleton instance;
       private static object syncRoot = new Object();

       private Singleton() {}

       public static Singleton Instance
       {
          get 
          {
             if (instance == null
             {
                lock (syncRoot) 
                {
                   if (instance == null
                      instance = new Singleton();
                }
             }

             return instance;
          }
       }
    }
  • 相关阅读:
    HDU 5001 Walk (暴力、概率dp)
    Codeforces Round #265 (Div. 2) C 暴力+ 找规律+ 贪心
    zoj 3812 We Need Medicine (dp 状压)
    ZOJ
    ZOJ 3811 / 2014 牡丹江赛区网络赛 C. Untrusted Patrol bfs/dfs/并查集
    POJ 2411 状压dp
    HDU 3001 三进制 状压dp
    POJ 2096 (dp求期望)
    poj 3311 状压dp 最短路
    数据挖掘的基本概念
  • 原文地址:https://www.cnblogs.com/cr7/p/2294053.html
Copyright © 2011-2022 走看看