It is getting ridiculous:
var input = "This is a test";
Meta Stack Exchange is a question and answer site for meta-discussion of the Stack Exchange family of Q&A websites. It only takes a minute to sign up.Sign up to join this community
This question appears to be off-topic. The users who voted to close gave this specific reason:
There's no doubt that
var can be overused. However, it can also aid readability by emphasizing how a variable is used rather than what its exact type is, and by reducing duplication.
Eric Lippert wrote a great comment about this topic when he was tech reviewing C# in Depth.
var has another very handy property in places where space is constrained - it's almost always shorter than the type name. This can be important in books and also on Stack Overflow where line lengths are fairly short.
More importantly, however, I don't think it's up to any one person to dictate the coding style used for answers. Go ahead and avoid using
var in your own answers. Criticise answers where the use of
var really, really leads to confusion... but accept that it's a personal preference.
var answer = "no";
Actually, I've noticed that too. Here's an extreme example:
Someone edited another user's answer from:
Int32 count = Enumerable.Intersect(listA, listB).Count(word => word.Length > 3);
var count = Enumerable.Intersect(listA, listB).Count(word => word.Length > 3);
I don't see any reason to do that - I wouldn't edit an answer to fit my coding standards.
As for weather
var is good or not, and best practice: that belongs on SO, but it has its downsides. Personally, I try not expose too much of it to beginners (or it gets too confusing / magical), especially not instead of
ints (as above) .