Home > OS >  disable warning "use var instead of explicit type" for certain types only
disable warning "use var instead of explicit type" for certain types only

Time:06-18

If I write code like this:

int five = 2 3;

VS warns me that I should "use var instead of explicit type". I'm actually ok with that warning in a lot of circumstances, but not here. The word "int" is just as short as "var" and a little more informative. So in this case, I think "int" is actually better.

Even in this case, I wish it wouldn't warn me:

bool ok = Condition1() && Condition2();

By contrast, I'm glad it warns me in a case like this:

MyReallyLongTypeName<LongTypeParameter> foo = SomeFunction();

So I guess I'm wondering if there is a way to disable that warning for a few types, but keep it for most types.

CodePudding user response:

In Visual Studio search for "preferences" enter image description here

Then search for "var"

enter image description here

There you can select if you prefer explicit types.

  • Related