コード例 #1
0
ファイル: Program.cs プロジェクト: lianrey/DesignPatterns
        public static void firstExample()
        {
            ReservationSingleton instance = ReservationSingleton.GetInstance();

            Console.WriteLine("1st instace ID " + RuntimeHelpers.GetHashCode(instance));

            ReservationSingleton instance2 = ReservationSingleton.GetInstance();

            Console.WriteLine("2nd instace ID " + RuntimeHelpers.GetHashCode(instance2));
        }
コード例 #2
0
ファイル: Program.cs プロジェクト: lianrey/DesignPatterns
        public static void secondExample()
        {
            Console.WriteLine("--------THREADS---------");

            new Thread(() =>
            {
                ReservationSingleton instance = ReservationSingleton.GetInstance();
                Console.WriteLine("1st thread instace ID " + RuntimeHelpers.GetHashCode(instance));
            }).Start();

            new Thread(() =>
            {
                ReservationSingleton instance = ReservationSingleton.GetInstance();
                Console.WriteLine("2nd thread instace ID " + RuntimeHelpers.GetHashCode(instance));
            }).Start();
        }