Search code examples
c#varimplicit-typing

Are implicitly-typed variables the way forward (C#)


I am using StyleCop for Resharper on a project originally written for .net v2. But I've since upgraded this project for 3.5 framework.

Stylecop is recommending I change the bulk of my explicitly typed variables to implicitly typed for example:

string - var

custom strong type - var

Is this the way forward when working with a .net 3.5 project. It seems unusual declaring everything as var.

Feel free to update the question title if my terminology is out...


Solution

  • Those are not generics, those are implicitly typed variables. This is really largely a matter of taste. There are places where you can overdo the use of var and there are places where it's very clearly necessary (think anonymous types) so just find the place in the middle that suits your (and your team's) preference.