开发者

What are the common "backing field" naming schemes in .net?

开发者 https://www.devze.com 2023-01-16 23:55 出处:网络
When doing a backing field for a property what are the common naming schemes? Edit: make question specif开发者_开发技巧ic to .netI usually use the property name itself, camel-cased and prefixed with

When doing a backing field for a property what are the common naming schemes?

Edit: make question specif开发者_开发技巧ic to .net


I usually use the property name itself, camel-cased and prefixed with an underscore:

private int _someProperty;
public int SomeProperty
{
    get { return _someProperty; }
    set { _someProperty = value; }
}

If you're using C# and the property is just a simple field accessor then you can use auto-implemented properties and the naming problem just disappears:

public string SomeOtherProperty { get; set; }


Conventions differ from language to language.

In Delphi, there's a very strong convention that internal member variables are prefixed with "F" for "Field".

public 
    property Name : string read FName write FName;

private
    FName : string;

In C++, there's a similar convention specifying underscore _ as the prefix.

Lots of C# developers use _ or m_ for members, though it's my understanding that Microsoft officially discourages this.

Update: Corrected an embarrasing mistake - the Delphi convention is F for field, not m for Member.


So far I have

  • Lower case first character.

    Property = GivenNames

    Field = givenNames

  • Under score first character.

    Property = GivenNames

    Field = _GivenNames

0

精彩评论

暂无评论...
验证码 换一张
取 消