0

(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?

Charlieface
  • 52,284
  • 6
  • 19
  • 43
  • 2
    in the olden days it was often used to mark a module level variable. Here that would mean a private class variable or field. Then in the less olden days it became more common to use an underscore (such as `_instance`). And now, it seems things are heading towards don't use either of these types of naming conventions (though I'm not sure why). In any case, `mInstance` is your private backing field. – topsail Sep 19 '22 at 17:35
  • 2
    This is called Hungarian Notation if you want to have a look into it. There is a good question about its drawbacks here: https://stackoverflow.com/questions/111933/why-shouldnt-i-use-hungarian-notation – Henry Twist Sep 19 '22 at 17:36

1 Answers1

2

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 _.

Markus
  • 20,838
  • 4
  • 31
  • 55