In the previous sections, you’ve seen a syntax used to declare and initialize local variables: specify the type, give the variable a name (lhs), and assign it some expression (rhs).
string name = "Bart";
Expressions, as you will see, always have a type. This means we have specified some redundant information to the compiler. On the left side, we called out a type explicitly, while the compiler could infer that information from the right side. In this case, the literal "Bart"
is of type System.String
. So why do we need to specify that type explicitly on the left?
var
KeywordUntil version 2.0 of ...
No credit card required