ReSharper的是正确的? [英] Is Resharper correct?

查看:161
本文介绍了ReSharper的是正确的?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

我应该做这些?

Should I do these?

我觉得在某些情况下,它会令code的可读性,但它会提高性能?是什么使得这些改​​变的好处是什么?

I think in some cases it is going to make the code less readable but will it improve performance? what are the benefits of making these changes?

感谢

推荐答案

1)显式指针只在必要的时候参考,否则是不明确的。由于 GetRuleViolations 是在类型定义的,你最有可能不需要

1) The explicit this pointer is only necessary when the reference would otherwise be ambiguous. Since GetRuleViolations is defined on the type, you most likely do not need this.

这里还有一点是,如果 GetRuleViolations 返回的IEnumerable 的东西,你一般会好得多使用任何()而不是计数()== 0 ,否则可能列举的整个序列。

Another point here is that if GetRuleViolations return an IEnumerable of something, you will generally be much better off using Any() instead of Count() == 0 as you risk enumerating the entire sequence.

2)String可以从初始化来推断。

2) String can be inferred from the initialization.

3)ReSharper的prefers VAR 对特定类型。

3) Resharper prefers var over specific types.

这篇关于ReSharper的是正确的?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆