Naming convention - underscore in C++ and C# variables

前端 未结 19 2338
春和景丽
春和景丽 2020-11-28 01:11

It\'s common to see a _var variable name in a class field. What does the underscore mean? Is there a reference for all these special naming conventions?

19条回答
  •  悲&欢浪女
    2020-11-28 01:44

    A naming convention like this is useful when you are reading code, particularly code that is not your own. A strong naming convention helps indicate where a particular member is defined, what kind of member it is, etc. Most development teams adopt a simple naming convention, and simply prefix member fields with an underscore (_fieldName). In the past, I have used the following naming convention for C# (which is based on Microsofts conventions for the .NET framework code, which can be seen with Reflector):

    Instance Field: m_fieldName
    Static Field: s_fieldName
    Public/Protected/Internal Member: PascalCasedName()
    Private Member: camelCasedName()

    This helps people understand the structure, use, accessibility and location of members when reading unfamiliar code very rapidly.

提交回复
热议问题