Singleton by Jon Skeet clarification

Posted by amutha on Stack Overflow See other posts from Stack Overflow or by amutha
Published on 2010-03-31T06:35:17Z Indexed on 2010/03/31 6:43 UTC
Read the original article Hit count: 864

Filed under:
|
|
public sealed class Singleton
{
    Singleton()
    {
    }

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

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

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

I wish to implement Jon Skeet's Singleton pattern in my current application in C#.

I have two doubts on the code

1) How is it possible to access the outer class inside nested class?

I mean internal static readonly Singleton instance = new Singleton(); Is something called closure?

2) I did not get this comment

// Explicit static constructor to tell C# compiler
            // not to mark type as beforefieldinit

what does this comment suggest us?

© Stack Overflow or respective owner

Related posts about ASP.NET

Related posts about c#