Skip to content

利用Lazy 实现单例模式 #5

@a34546

Description

@a34546

Lazy 是线程安全的,可以利用Lazy很简单的实现单例模式

    public class Singleton
    {
        private static readonly Lazy<Singleton> singletonLazy = new Lazy<Singleton>(() => new Singleton());
        public static Singleton Instance => singletonLazy.Value;
    }

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions