问题描述
这是常见的一类现场看到 _var
变量名。什么是底线是什么意思?是否有所有这些特殊的命名约定的参考?
It's common to see a _var
variable name in a class field. What does the underscore mean? Is there a reference for all these special naming conventions?
推荐答案
下划线是一个简单的约定;而已。因此,它的使用是总是向每个人有所不同。以下是我理解他们的两种语言问题:
The underscore is simply a convention; nothing more. As such, its use is always somewhat different to each person. Here's how I understand them for the two languages in question:
在C ++中,下划线通常表明一个私有成员变量。
In C++, an underscore usually indicates a private member variable.
在C#中,我通常看到的只是定义底层的私有成员变量的公共财产时使用。其他私有成员变量不会有下划线。这种用法在很大程度上去路边有自动属性的出现虽然。
In C#, I usually see it used only when defining the underlying private member variable for a public property. Other private member variables would not have an underscore. This usage has largely gone to the wayside with the advent of automatic properties though.
在
private string _name;
public string Name
{
get { return this._name; }
set { this._name = value; }
}
在
public string Name { get; set; }
这篇关于命名约定 - 在C ++中强调和C#变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!