示例一:
public class SpiderService { private static SpiderService instance; public static SpiderService Instance { get { if (instance == null) { instance = new SpiderService(); } return instance; } } }
通过SpiderService.Instance访问方法。
示例二:
public sealed class Singleton { private static readonly Lazy<Singleton6> lazy = new Lazy<Singleton>(()=> new Singleton()); public static Singleton Instance { get { return lazy.Value; } } private Singleton() { } }
标签:Singleton,示例,C#,public,instance,static,单例,SpiderService From: https://www.cnblogs.com/mauistudio/p/17933353.html