Rig*_*ong 6 .net c# coding-style
我刚刚安装了Reshaper 4.5,它提出了以下建议:
return this.GetRuleViolations().Count() == 0; -- REMOVE this.
new string[] { this.ID.ToString(), this.Registration } -- REMOVE string, MAKE ANONYMOUS TYPE
int i = Method.GetNumber(); -- REPLACE int WITH var
Run Code Online (Sandbox Code Playgroud)
我应该这样做吗?
我认为在某些情况下,它会降低代码的可读性,但会提高性能吗?进行这些更改有什么好处?
谢谢
Bri*_*sen 12
1)this只有当引用不明确时才需要显式指针.由于GetRuleViolations在类型上定义,您很可能不需要this.
这里的另一点是,如果GetRuleViolations返回一个IEnumerable东西,你通常会更好地使用Any()而不是Count() == 0冒险枚举整个序列.
2)字符串可以从初始化推断出来.
3)Resharper喜欢var特定类型.