码迷,mamicode.com
首页 > 其他好文 > 详细

单例模式

时间:2016-05-14 10:17:33      阅读:130      评论:0      收藏: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     }

 

单例模式

标签:

原文地址:http://www.cnblogs.com/yingchuanxiaoge/p/5491901.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!