单例模式

mac2022-06-30  22

1、Person类里面

class Person { private static Person p; public static Person GetSingle() { if (p == null) { p = new Person(); } return p; } private Person() { } }

2、Program类里面

class Program { static void Main(string[] args) { Person p = Person.GetSingle(); } }

 

转载于:https://www.cnblogs.com/ruanmou001/p/3446027.html

相关资源:JAVA上百实例源码以及开源项目
最新回复(0)