www.softwareriviera.com
Software Code
    New Code     Most Interesting     Don't Miss     Our picks  
C# - section

View Article
Singleton implementation in C#
See how you can implement a singleton class in C#. This is useful when you want to create only one instance of a class and provide only one point of access to that class.
The code below creates a singleton class in C#. This is useful when you want to create only one instance of a class and provide only one point of access to that class.

Once implemented you can access the class using the following:
AppCurrentContext.GetInstance().MethodName()
AppCurrentContext.GetInstance().PropertyName

Here is the singleton implementation:
public class AppCurrentContext
{
static AppCurrentContext _appCurrentInstance;

//add members here
//...

AppCurrentContext()
{
}

public static AppCurrentContext GetInstance()
{
if (_appCurrentInstance == null)
_appCurrentInstance = new AppCurrentContext();
return _appCurrentInstance;
}
}
Date: 2012-5-30    Written by: Admin A
     See all articles in this section
Copyright © 2007-2009 SoftwareRiviera.com. All rights reserved.  | Terms of use | Disclaimer | Privacy Policy |