程序员面试题精选100题(56)-C/C++/C#面试题(4)(7)

时间:2019-09-22 编辑:多美文

        private static Singleton1 instance = new Singleton1();

        public static Singleton1 Instance

        {

            get

            {

                return instance;

            }

        }

    }

 

    public sealed class Singleton2

    {

        Singleton2()

        {

            Console.WriteLine("Singleton2 constructed");

        }

        public static void Print()

        {

            Console.WriteLine("Singleton2 Print");

        }

        public static Singleton2 Instance

        {

            get

            {

                return Nested.instance;

            }

        }

        class Nested

        {

            static Nested() { }

 

            internal static readonly Singleton2 instance = new Singleton2();

        }

    }

本文已影响
相关文章