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

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.
主站蜘蛛池模板: 射洪县| 区。| 扬中市| 筠连县| 越西县| 黎平县| 共和县| 钦州市| 南江县| 荣成市| 澄城县| 绥德县| 甘洛县| 建瓯市| 定兴县| 额尔古纳市| 镇江市| 永胜县| 鹤壁市| 遵义县| 万载县| 新宾| 盐津县| 曲水县| 眉山市| 涟源市| 达拉特旗| 北京市| 肥东县| 云梦县| 罗田县| 赤壁市| 永新县| 无棣县| 万年县| 荆门市| 肇州县| 洪湖市| 沙湾县| 乌鲁木齐市| 苏尼特左旗|