Created
February 2, 2016 11:04
-
-
Save sudipto80/790cb1aacf6b9b1e341d to your computer and use it in GitHub Desktop.
SingletonInput1
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/// <summary> | |
/// Sample singleton object. | |
/// </summary> | |
public sealed class SiteStructure | |
{ | |
/// <summary> | |
/// This is an expensive resource. | |
/// We need to only store it in one place. | |
/// </summary> | |
object[] _data = new object[10]; | |
/// <summary> | |
/// Allocate ourselves. | |
/// We have a private constructor, so no one else can. | |
/// </summary> | |
static readonly SiteStructure _instance = new SiteStructure(); | |
/// <summary> | |
/// Access SiteStructure.Instance to get the singleton object. | |
/// Then call methods on that instance. | |
/// </summary> | |
public static SiteStructure Instance | |
{ | |
get { return _instance; } | |
} | |
/// <summary> | |
/// This is a private constructor, meaning no outsiders have access. | |
/// </summary> | |
private SiteStructure() | |
{ | |
// Initialize members here. | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment