コード例 #1
0
        static void Main(string[] args)
        {
            SingletonClass singletonOne = SingletonClass.Instance;

            singletonOne.ShowMessage();
            SingletonClass singletonTwo = SingletonClass.Instance;

            DoWork(singletonTwo);

            // потокобезопасная реализация
            (new Thread(() =>
            {
                ThreadSafeSingleton instanceOne = ThreadSafeSingleton.Instance;
            }
                        )).Start();
            ThreadSafeSingleton instanceTwo = ThreadSafeSingleton.Instance;


            Console.ReadLine();
        }
コード例 #2
0
 private static void DoWork(SingletonClass singleton)
 {
     singleton.ShowMessage();
 }