Usage of the C# var keyword. Is there a Best Practice?
The C# var keyword was introduced in C# version 3.0. According to Eric Lippert from the Microsoft C# team it was included for 2 primary reasons:
1) To limit redundant code, such as:
and write is as
2) To support anonymous types, which were necessary to implement LINQ, such as:
Now, much of the code you see floating around on the Internet coming from experts use vars just about anywhere where it can be used. However, I have developed a personal preference, i.e. best practice if you will, that goes like this:
Henry Wong, Mar 17, 2011
Some good points Henry. You may be interested in this discussion as well. And yes, anonymous types, that's pretty useful for jquery/json scenarios...
Rajesh Pillai, Mar 17, 2011