2

var keyword in C# is pretty useful, since it is much shorter to write and does not change the compiled program. Hovering over var keyword in Visual Studio shows a tool tip with the "real" variable type behind, which is nice too.

But in most of the cases, having full qualified type instead of var makes code more readable. When there are ten vars in ten lines of code, each one having its own underlying type, it becomes more difficult to quickly understand the source code.

Is there an add-in or a tool which replaces all vars by explicitly defined variable types in selected text?

Arseni Mourzenko
  • 50,338
  • 35
  • 112
  • 199
  • 1
    See [Resharper: vars](http://stackoverflow.com/questions/296783/resharper-vars) and [Tool to refactor C# var to explicit type](http://stackoverflow.com/questions/289743/tool-to-refactor-c-var-to-explicit-type). – Matthew Flaschen Jul 12 '10 at 02:01
  • 1
    possible duplicate of [Tool to refactor C# var to explicit type](http://stackoverflow.com/questions/289743/tool-to-refactor-c-var-to-explicit-type) – David Hall Jul 12 '10 at 02:03
  • 1
    I don't happen to agree with the premise, but aside from that, I should probably point out that not all instances of `var` can be replaced. In specific, there's no equivalent way to refer to anonymous types. I'm sure you find this obvious, but I'm commenting on this for others. – Steven Sudit Jul 12 '10 at 02:28
  • Old thread, I was actually searching on how to do the reverse. I think var is preferrable because it removes duplication. eg "MyWindow window = new MyWindow()". If we want to change to use SomeOtherWindow then we need to change it in 2 places. Surely that is not a good thing. – MikeKulls Sep 27 '12 at 04:58

1 Answers1

3

Yes.

Resharper.

SLaks
  • 868,454
  • 176
  • 1,908
  • 1,964