class Singleton
{
private static Singleton instance;
private static int numOfReference;
private string code;
private Singleton()
{
numOfReference = 0;
code = "Maasoom Faraz";
}
public static Singleton GetInstance()
{
if (instance == null)
{
instance = new Singleton();
}
numOfReference++;
return instance;
}
public static int Reference
{
get { return numOfReference; }
}
public string Code
{
get { return code; }
set { code = value; }
}
}
calling
============
Singleton obj1 = Singleton.GetInstance();
Singleton obj2 = Singleton.GetInstance();
obj1.Code = "Faraz Rasheed";
Console.WriteLine("No. of references : " + Singleton.Reference);
Console.WriteLine("First Objects code: " + obj1.Code);
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment