Code casing question for private class fields
Posted
by user200295
on Stack Overflow
See other posts from Stack Overflow
or by user200295
Published on 2010-03-16T13:33:23Z
Indexed on
2010/03/16
13:36 UTC
Read the original article
Hit count: 181
c#
|best-practices
Take the following example
public class Class1{
public string Prop1{
get {return m_Prop1;}
set {m_Prop1 = value; }
}
private string m_Prop1; // this is standard private property variable name
// how do we cap this variable name? While the compiler can figure out same casing
// it makes it hard to read
private Class2 Class2;
// we camel case the parameter
public Class1(Class2 class2){
this.Class2 = class2;
}
}
Here are my stock rules
- The class name is capitalized (Class1)
- The public properties are capitalized (Prop1)
- The private field tied to a public property has m_ to indicate this. My coworker prefers _ There is some debate if using m_ or _ should be used at all, as it is like Hungarian notation.
- Private class fields are capitalized.
The part I am trying to figure out is what do I do if when the Class name of a private field matches the private field name. For example, private Class2 Class2; This is confusing.
If the private field name is not the same class, for example private string Name; , there isn't much issue.
Or am I thinking about the issue wrong. Should my classes and private fields be named in such a way that they don't collide?
© Stack Overflow or respective owner