Currently Being Moderated

Why ReSharper always suggests to use vars instead of explicit type usages?

VERSION 1

Created on: Jun 10, 2008 11:39 AM by Andrey Serebryansky - Last Modified:  Jun 10, 2008 11:39 AM by Andrey Serebryansky

This suggestion is turned on by default. You can disable this suggestion through ReSharper > Options > Code Inspections > Inspection Severity

Average User Rating
(12 ratings)




khooroos  khooroos  says:

I still don't know why an implicit declaration is preferred so that JetBrains decided to keep the above toggle on by default.

Bill Richards Bill Richards  says in response to khooroos:

Implicit variable declaration is preferred because ...

 

It forces you to put some thought into your variable name.

 

int j = 10;

for(int i = 0; i < j; i++) { }

 

versus:

 

var upperBoundsOfCollection = 10;

for (var index = 0; index < upperBoundsOfCollection; index++) { }

 

when you have the type written there in front of your variable declaration, you are ALSWAYS tempted to give your variable a non-meaningful name. When there is no type specified, you are more likely to name your variables in such a manner that you know what it is for and why it is there.

More Like This

  • Retrieving data ...