Search code examples
c#notation

What does "m" stand for in relation to singleton pattern?


(I have tried searching for "singleton pattern what does m stand for" with no result, but there is a lot of code online with variable names called mInstance.) Code looks something like this:

internal sealed class ClassName
{
    private static ClassName mInstance;
    public static ClassName Instance
    {
        get
        {
            if (mInstance == null)
            {
                mInstance = new ClassName();
            }
            return mInstance;
        }
    }
}

This is clearly a singleton class, but I have no idea why "mInstance" is called "mInstance". Do you know what "m" stands for?


Solution

  • The m is not related to the singleton pattern, but most likely denotes an internal member field (private, protected) of the class. Other conventions are to start such members with m_ or just an underscore _.