using System; |
using System.Collections.Generic; |
using System.Text; |
namespace 单例模式 |
{ |
class Singleton |
{ |
private static Singleton instance; |
private Singleton() { } |
public static Singleton GetInstance() |
{ |
if ( instance == null ) |
instance = new Singleton(); |
return instance; |
} |
} |
class Program |
{ |
static void Main ( string [] args ) |
{ |
Singleton s1 = Singleton.GetInstance(); |
Singleton s2 = Singleton.GetInstance(); |
if ( s1 == s2 ) |
Console.WriteLine ( "两个对象是相同的实例!" ); |
Console.Read(); |
} |
} |
} |
by: 发表于:2018-01-31 15:10:46 顶(0) | 踩(0) 回复
??
回复评论