C#风格问题、变量名和;类属性名
试着按书办事,对吗C#风格问题、变量名和;类属性名,c#,naming-conventions,coding-style,C#,Naming Conventions,Coding Style,试着按书办事,对吗 public class JollyHockey { public string AnotherCoolProperty { get { return anotherCoolProperty; } } string anotherCoolProperty; public JollyHockey(string anotherCoolProperty) { this.anotherCoolProperty = anotherC
public class JollyHockey
{
public string AnotherCoolProperty { get { return anotherCoolProperty; } }
string anotherCoolProperty;
public JollyHockey(string anotherCoolProperty)
{
this.anotherCoolProperty = anotherCoolProperty;
}
}
或者有些人对私有类变量使用下划线?或者您可以这样做:
public class JollyHockey
{
public string AnotherCoolProperty { get; private set; }
public JollyHockey(string anotherCoolProperty)
{
this.AnotherCoolProperty = anotherCoolProperty;
}
}
或者您可以这样做:
public class JollyHockey
{
public string AnotherCoolProperty { get; private set; }
public JollyHockey(string anotherCoolProperty)
{
this.AnotherCoolProperty = anotherCoolProperty;
}
}
有些人(包括我自己)在私有类变量前面加下划线(只是为了直观地指示在哪里使用了什么)
这主要是个人(或团队)层面的风格考虑,你可以使用你想要的(或你的团队已经标准化的)
只要确保你是始终如一的
为了实现其价值,您还可以在示例中使用“自动属性”:
public class JollyHockey
{
public string AnotherCoolProperty { get; private set; }
public JollyHockey(string anotherCoolProperty)
{
AnotherCoolProperty = anotherCoolProperty;
}
}
有些人(包括我自己)在私有类变量前面加下划线(只是为了直观地指示在哪里使用了什么)
这主要是个人(或团队)层面的风格考虑,你可以使用你想要的(或你的团队已经标准化的)
只要确保你是始终如一的
为了实现其价值,您还可以在示例中使用“自动属性”:
public class JollyHockey
{
public string AnotherCoolProperty { get; private set; }
public JollyHockey(string anotherCoolProperty)
{
AnotherCoolProperty = anotherCoolProperty;
}
}
我相信您的示例符合MS编码准则。然而,我不喜欢,这是你们团队可以同意的
我不喜欢它的原因是因为基础字段名经常与方法参数冲突。我用下划线说明它们是私有变量。我相信您的示例符合MS编码准则。然而,我不喜欢,这是你们团队可以同意的
我不喜欢它的原因是因为基础字段名经常与方法参数冲突。我使用下划线来明确它们是私有变量。当函数参数与私有字段同名时 我通常用下划线作为参数的前缀 我认为这是有道理的
fletcher的ReSharper是个好主意当函数参数与私有字段同名时 我通常用下划线作为参数的前缀 我认为这是有道理的
fletcher的ReSharper thing是个好主意下载ReSharper试用版并使用几周。这就把各种行业标准命名约定和小的重构推到了你的面前,包括你在这里谈论的内容。下载ReSharper试用版并使用它几周。这就把所有类型的行业标准命名约定和小的重构推到了你的面前,包括你在这里谈论的内容。我比贾斯汀·尼斯纳更喜欢你的答案,因为在私有变量前面加下划线对我来说真的很难看+1.建议私人设定者。我比贾斯汀·尼斯纳更喜欢你的答案,因为在私有变量前面加下划线对我来说真的很难看从未听说过汽车产业。好极了从未听说过汽车产业。好极了