All is fair in love and var

The var keyword in C# 3.0 has been the subject of much scorn recently, which I feel is uncalled for. It is really a matter of personal preference - I use the var keyword in LINQ queries, and I think there's no other good way of storing the output of a LINQ query. Implicit typing is just an equally strong typing convention as explicit typing as the compiler determines the actual type, never so wrongly.

Anonymous types are, to me, a blessing of LINQ, and there's no better way to save variables of anonymous types than in a var. Using the var keyword in any context other than LINQ, however, would be undesirable, as readability can be compromised and the code would unnecessarily be cluttered.

1 comment:

  1. The concept of "var" is really interesting at first thought but only useful commercially in my perspective in LINQ.

    Though people who use C# and can't seem to remember the datatypes of variables can put this feature to an extra-ordinary use :)