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

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.
主站蜘蛛池模板: 锦州市| 绥阳县| 独山县| 普安县| 响水县| 顺平县| 日照市| 新巴尔虎右旗| 敦化市| 都江堰市| 永昌县| 威信县| 女性| 嘉荫县| 原平市| 桦川县| 德安县| 龙南县| 石林| 泽普县| 香港| 宜丰县| 丰台区| 科尔| 苏尼特右旗| 涞源县| 香港| 筠连县| 威远县| 临桂县| 利川市| 大余县| 宝应县| 广灵县| 三原县| 当阳市| 江源县| 永靖县| 鹤岗市| 奎屯市| 九龙城区|