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

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.
主站蜘蛛池模板: 乐山市| 突泉县| 中宁县| 岫岩| 西吉县| 冕宁县| 志丹县| 封开县| 曲阜市| 沾化县| 长顺县| 舞钢市| 兴义市| 奉化市| 札达县| 阿拉善右旗| 安仁县| 滦平县| 鸡泽县| 蒙阴县| 万州区| 星座| 通城县| 沾益县| 特克斯县| 肇东市| 汨罗市| 内丘县| 斗六市| 金山区| 抚顺市| 育儿| 镇安县| 松潘县| 黄梅县| 原阳县| 香港 | 西畴县| 吐鲁番市| 淄博市| 扶绥县|