Choosing naming conventions for class fields in C #?
I have seen several naming conventions used for fields in C #. It:
Underline
public class Foo
{
private string _name;
public string Name
{
get { return _name; }
set { _name = value; }
}
}
it
public class Foo
{
private string name;
public string Name
{
get { return this.name; }
set { this.name = value; }
}
}
Member prefix
public class Foo
{
private string m_name;
public string Name
{
get { return m_name; }
set { m_name = value; }
}
}
What do you prefer? Is there any other way that you would rather do? Just curious to know what others think is best practice.
+1
a source to share
4 answers
1) This is a purely stylistic / subjective question, so one tends to be as good as the other. (I believe that since the last time I answered such a question, even with almost the same qualifications, I had different people who voted for me and said that I was wrong.)
2) I am using the method this
. This is the default technology used by StyleCop and I have no other source code analysis tool available to me at the moment. This is perfectly acceptable.
0
a source to share