Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is Resharper correct?

I just installed Reshaper 4.5 and it has come up with the following suggestions:

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?

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?

Thanks

like image 619
Rigobert Song Avatar asked Aug 19 '09 10:08

Rigobert Song


People also ask

Why should I use ReSharper?

Eliminate errors and code smells Not only does ReSharper warn you when there are problems in your code but it provides quick-fixes to solve them automatically.

Does ReSharper Support VS 2022?

ReSharper 2021.3 release supports Visual Studio 2022 out-of-the-box.

Does ReSharper slow down Visual Studio?

Resharper is a great Visual Studio productivity extension but on the other hand it slows down significantly the IDE, especially when working with large solutions.

How do I know if ReSharper is working?

The power of Alt+Enter icon, this means ReSharper has detected an error or other code issue and it can help you fix it. Press Alt+Enter to take advantage of this. For more information, see Quick-fixes for code issues.


1 Answers

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.

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 can be inferred from the initialization.

3) Resharper prefers var over specific types.

like image 107
Brian Rasmussen Avatar answered Oct 23 '22 12:10

Brian Rasmussen