官术网_书友最值得收藏!

Reassigning values to inferred variables

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 variable query

The type of a local variable defined using var is inferred only once.
主站蜘蛛池模板: 托克托县| 军事| 方城县| 苏尼特左旗| 西乡县| 中卫市| 高阳县| 许昌市| 荆门市| 丹江口市| 镇平县| 太仆寺旗| 井陉县| 瑞安市| 迁安市| 盐源县| 南岸区| 长丰县| 都江堰市| 阿拉善左旗| 鄢陵县| 秦皇岛市| 田林县| 东海县| 兴隆县| 蒲城县| 安阳市| 锡林浩特市| 都江堰市| 福海县| 固始县| 汉中市| 绥芬河市| 莱阳市| 唐山市| 鲁甸县| 合肥市| 迁西县| 庆城县| 玉门市| 河北区|