Skip to content

Instantly share code, notes, and snippets.

@sudipto80
Created February 2, 2016 11:04
Show Gist options
  • Save sudipto80/790cb1aacf6b9b1e341d to your computer and use it in GitHub Desktop.
Save sudipto80/790cb1aacf6b9b1e341d to your computer and use it in GitHub Desktop.
SingletonInput1
/// <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