您好,登錄后才能下訂單哦!
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; //Singleton設計模式(單實例) namespace ConsoleApplication6 { class Program { static void Main(string[] args) { //案例: Singleton s = Singleton.getSingleton(); s.name = "asd"; Singleton s1 = Singleton.getSingleton(); s1.ShowMsg(); Console.ReadKey(); } } class Singleton { //靜態(tài)類(自己) private static Singleton singleton = null; //私有構造函數(shù) private Singleton() { } public static Singleton getSingleton() { if (singleton == null) singleton = new Singleton();//實例化 return singleton; } public string name { get; set; } public void ShowMsg() { Console.WriteLine(name); } } }
免責聲明:本站發(fā)布的內容(圖片、視頻和文字)以原創(chuàng)、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯(lián)系站長郵箱:is@yisu.com進行舉報,并提供相關證據(jù),一經查實,將立刻刪除涉嫌侵權內容。