Is there any C# naming convention for a variable used in a property?

后端 未结 12 1687
无人及你
无人及你 2021-01-31 07:26

Let\'s say, we have a variable, which we want named Fubar

Let\'s say that Fubar is a String!

That means, we would define F

12条回答
  •  终归单人心
    2021-01-31 08:14

    Well, the Framework Design Guidelines document states the following:

    Names of Fields The field-naming guidelines apply to static public and protected fields. Internal and private fields are not covered by guidelines, and public or protected instance fields are not allowed by the member design guidelines.

    ✓ DO use PascalCasing in field names.

    ✓ DO name fields using a noun, noun phrase, or adjective.

    X DO NOT use a prefix for field names.

    For example, do not use "g_" or "s_" to indicate static fields.

    So, for private fields, there is no official recommendation. However, if you use VS 2017 quick action "Convert to full property" on a property, this happens:

    So it seems like it is safe to assume that prefixing private fields with an underscore is somewhat standard.

提交回复
热议问题