"m_" prefix in classes

  • Thread starter Thread starter Internet User
  • Start date Start date
I

Internet User

I see m_ prefixed in front of variable names all the time in code for
classes. Is this a coding convention and if so how does one describe the
type of variables it is used with?

Thanks in advance.
 
I see m_ prefixed in front of variable names all the time in code for
classes. Is this a coding convention and if so how does one describe the
type of variables it is used with?

m_ means member variable ... a class level variable.

just _ i.e. Dim _MyVariable as String is used for local variables.

But it's personal preference. Microsoft had a naming guide online, but from
what I recall it wasn't all that indepth.
 
Internet User said:
I see m_ prefixed in front of variable names all the time in code for
classes. Is this a coding convention and if so how does one describe the
type of variables it is used with?

'm_' is typically used to mark private variables in order to make their
scope more visible and to prevent name clashes with the class' public
properties. Imagine a class having a 'UserName' property. The property's
value could be stored in a private "backing field" named 'm_UserName', for
example.

To me the 'm' stands for "module-level" (module = module, structure, class)
opposed to 'g' which stands for "global" (and which I am using almost
never).
 
Thanks.

Spam Catcher said:
m_ means member variable ... a class level variable.

just _ i.e. Dim _MyVariable as String is used for local variables.

But it's personal preference. Microsoft had a naming guide online, but
from
what I recall it wasn't all that indepth.
 
Thanks. Exactly what I needed.

Herfried K. Wagner said:
'm_' is typically used to mark private variables in order to make their
scope more visible and to prevent name clashes with the class' public
properties. Imagine a class having a 'UserName' property. The property's
value could be stored in a private "backing field" named 'm_UserName', for
example.

To me the 'm' stands for "module-level" (module = module, structure,
class) opposed to 'g' which stands for "global" (and which I am using
almost never).
 
It's an old VB coding convention meaning module. The scope is class-wide,
i.e., a Private variable.
 
Earl said:
It's an old VB coding convention meaning module. The scope is class-wide,
i.e., a Private variable.

IIRC the convention has been "borrowed" from C++, but it's hard to determine
the exact roots of it.
 
Back
Top