Why Use var?

Ever since the var keyword was released in C#, I’ve struggled with using it. To me var felt like using variant or object in VB, even though logically I know it is not.

List<string> items = new List<string>();
vs.
var items = new List<string>();

Since I bought Resharper, it’s been nagging me to use var in my declarations, so I  have acquiesced. Today that paid off. I had to refactor something which caused a few type changes. It was so much easier to deal with because I used var instead of writing out the declaration the old way, there were just fewer changes. I’m now a complete convert to var, thanks Resharper.

Posted on:

Comments are closed.