C# Lazy Loading Implementation of Singleton Pattern

2020年5月7日 56点热度 0人点赞 0条评论
内容目录

Besides manually implementing the singleton pattern, you can also use the Lazy generic type to implement the singleton pattern.

    public sealed class Singleton
    {
        private static readonly Lazy<Singleton> lazy = new Lazy<Singleton>(() => new Singleton());
        public static Singleton Instance { get { return lazy.Value; } }
        private Singleton()
        {

        }
    }

痴者工良

高级程序员劝退师

文章评论