views:

46

answers:

3

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

Edit: make question specific to .net

A: 

So far I have

  • Lower case first character.

    Property = GivenNames

    Field = givenNames

  • Under score first character.

    Property = GivenNames

    Field = _GivenNames

Simon
+3  A: 

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; }
LukeH
I like this one.
Alex
+1  A: 

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.

Bevan