C# 泛型懒汉单例类

C# 泛型懒汉单例类

using System;

namespace SingletonHepler
{
    public sealed class Singleton<T> where T : class, new()
    {
        private static readonly Lazy<T> _instance = new Lazy<T>(() => new T());

        public static T Instance => _instance.Value;

        // 防止外部初始化
        private Singleton() { }
    }
}
posted @ 2025-10-14 16:28  杰西卡若  阅读(8)  评论(0)    收藏  举报