导航

单例模式

Posted on 2016-05-14 09:00  颍川小哥  阅读(120)  评论(0编辑  收藏  举报

构造类

 1  class God
 2     {
 3         private static God Instance = new God();
 4         private God() { }
 5         
 6         public void ZhaoYaoDaDi()
 7         {
 8             Console.WriteLine("照耀大地");
 9         }
10         public static God GetInstace()
11         {
12             return Instance;
13         }
14     }

调用

 1 class Program
 2     {
 3         static void Main(string[] args)
 4         {
 5             // God d1 = new God();
 6 
 7             God.GetInstace().ZhaoYaoDaDi();
 8             //God.Instance.ZhaoYaoDaDi();
 9             Console.ReadKey();
10 
11         }
12     }