C#中类字段的命名首选项? [英] Naming Preference for class fields in C#?
本文介绍了C#中类字段的命名首选项?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我已经看到了C#中用于字段的几种命名约定.他们是:
I have seen several naming conventions used for fields in C#. They are:
下划线
public class Foo
{
private string _name;
public string Name
{
get { return _name; }
set { _name = value; }
}
}
此
public class Foo
{
private string name;
public string Name
{
get { return this.name; }
set { this.name = value; }
}
}
成员前缀
public class Foo
{
private string m_name;
public string Name
{
get { return m_name; }
set { m_name = value; }
}
}
您更喜欢哪个?您喜欢采用其他方式吗?只是想知道别人的感觉是一种最佳做法.
Which do you prefer? Is there a different way you prefer to do it? Just curious to know what others feel is a best practice.
推荐答案
我通常使用:
public class Foo
{
private string name;
public string Name
{
get { return name; }
set { name = value; }
}
}
只是删除了这个.因为它很多余
just removed the this. since it's rather redundant
这篇关于C#中类字段的命名首选项?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文