示例#1
0
        static void TestSimple()
        {
            SingltonClass s1 = SingltonClass.GetInstance();

            Console.WriteLine(s1.GetHashCode());

            SingltonClass s2 = SingltonClass.GetInstance();

            Console.WriteLine(s2.GetHashCode());
        }
示例#2
0
        static void TestThresd()
        {
            (new Thread(() =>
            {
                SingltonClass s1 = SingltonClass.GetInstance();
                Console.WriteLine(s1.GetHashCode());
            })).Start();
            SingltonClass s2 = SingltonClass.GetInstance();

            Console.WriteLine(s2.GetHashCode());
        }
示例#3
0
 public static SingltonClass GetInstance()
 {
     if (_singltonClass == null)
     {
         lock (_locker)
         {
             if (_singltonClass == null)
             {
                 _singltonClass = new SingltonClass();
             }
         }
     }
     return(_singltonClass);
 }