Thursday, July 23, 2009

Singleton Pattern

Using System;
Using System.Text;
Namespace Singletonproject
Class Singleton
{
Private Datetime CreatedDateTime;
Private Singleton
{
CreatedDateTime = System.DateTime.Now;
}
Private static Singleton instancia = null;
Private Object Padlock = new object();
Public Singleton Instancia
{
get{
if(instancia==null)
instancia= new Singleton();
return instancia;
}
}
Public string GetDateTime
{
return CreatedDateTime.Tostring();
}
Calling procedure
Singletonproject.Singleton clsc= Singletonproject.Singleton.Instancia;
Label1.text = clsc.GetDateTime.Tostring();

No comments: