March 2019
Intermediate to advanced
242 pages
6h 21m
English
As is applicable to all non-final variables, you can reassign value to inferred variables. Just ensure that the reassigned value matches its inferred type. In the following code, since the type of the age variable is inferred as int, you can't assign a decimal value of 10.9 to it. Similarly, since the type of the query variable is inferred as StringBuilder. The type of a variable is inferred just once, as follows:
var age = 9; // type of variable age inferred as int
age = 10.9; // can't assign 10.9 to variable of type int
var query = new StringBuilder("SELECT"); // Type of variable // query is StringBuilder
query = query.toString() + "FROM" + "TABLE"; // won't compile;
// can't assign String // to ...Read now
Unlock full access