Skip to content

Instantly share code, notes, and snippets.

@yakaas
Last active January 18, 2016 21:59
Show Gist options
  • Select an option

  • Save yakaas/e38db9a15fcbcde05f27 to your computer and use it in GitHub Desktop.

Select an option

Save yakaas/e38db9a15fcbcde05f27 to your computer and use it in GitHub Desktop.

Revisions

  1. yakaas revised this gist Jan 18, 2016. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion Singleton
    Original file line number Diff line number Diff line change
    @@ -1,4 +1,4 @@
    // http://csharpindepth.com/Articles/General/Singleton.aspx
    // http://csharpindepth.com/Articles/General/Singleton.aspx#nested-cctor

    public sealed class Singleton
    {
  2. yakaas created this gist Jan 18, 2016.
    21 changes: 21 additions & 0 deletions Singleton
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,21 @@
    // http://csharpindepth.com/Articles/General/Singleton.aspx

    public sealed class Singleton
    {
    private Singleton()
    {
    }

    public static Singleton Instance { get { return Nested.instance; } }

    private class Nested
    {
    // Explicit static constructor to tell C# compiler
    // not to mark type as beforefieldinit
    static Nested()
    {
    }

    internal static readonly Singleton instance = new Singleton();
    }
    }