zoukankan      html  css  js  c++  java
  • C# 设计模式

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    namespace DBImportTool.Sgile
    {
        //第一种单例模式Demo
        public class A
        {
            private volatile static A _instance = null;
            private static readonly object lockHelper = new object();
            private A() { }
            public static A CreateInstance()
            {
                // 判断如果没有实例过,则进行实例化创建.
                
    // 瞬间触发量不高的网站,不需要此判断步骤.
                if (_instance == null)
                {
                    //锁机制.防止重复实例化.
                    lock (lockHelper)
                    {
                        if (_instance == null)
                        {
                            _instance = new A();
                        }
                    }
                }
                return _instance;
            }
        }

        //第二种单例模式Demo
        public sealed class B
        {
     
            B() { }
            public static B GetInstance()
            {
                return B1.b;
            }
            class B1
            {
                static B1()
                {
                }
                internal static readonly B b = new B();
            }
        }
    }
  • 相关阅读:
    NIOS II常用函数整理
    C指针
    YCbCrYUV
    指针与引用的区别
    Pacman 命令详解
    DDR工作原理
    关于C/C++中的点操作符和箭头操作符
    千兆以太网芯片88E1111 RGMII模式的驱动
    关于建立时间和保持时间
    ECE 576 UDP Hardware
  • 原文地址:https://www.cnblogs.com/mcqueen/p/4023768.html
Copyright © 2011-2022 走看看