我刚刚安装了 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
我应该做这些吗?
我认为在某些情况下它会降低代码的可读性,但它会提高性能吗?进行这些更改有什么好处?
谢谢
最佳答案
1) 显式的 this
指针只有在引用不明确时才需要。由于 GetRuleViolations
是在类型上定义的,因此您很可能不需要 this
。
这里的另一点是,如果 GetRuleViolations
返回某个东西的 IEnumerable
,您通常最好使用 Any()
而不是Count() == 0
因为您冒着枚举整个序列的风险。
2) 可以从初始化中推断出字符串。
3) Resharper 比特定类型更喜欢 var
。
关于c# - Resharper 正确吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1299045/