示例#1
0
        public MySingleObj GetInstance()
        {
            if (obj == null)
            {
                obj = new MySingleObj();
            }

            return(obj);
        }
示例#2
0
        /// <summary>
        /// 线程安全
        /// </summary>
        /// <returns></returns>
        public MySingleObj GetInstance1()
        {
            //过滤掉是null的
            if (obj == null)
            {
                //多个线程 都是null的话让一个进来
                lock (lockobj)
                {
                    //实例化一次
                    if (obj == null)
                    {
                        obj = new MySingleObj();
                    }
                }
            }

            return(obj);
        }