国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁(yè) > 學(xué)院 > 開(kāi)發(fā)設(shè)計(jì) > 正文

GO Short variable declarations短變量聲明

2019-11-06 06:44:20
字體:
來(lái)源:轉(zhuǎn)載
供稿:網(wǎng)友

A short variable declaration uses the syntax:

IdentifierList := ExPRessionList

It is shorthand for a regular variable declaration with initializer expressions but no types:var IdentifierList = ExpressionList

example:

i, j := 0, 10f := func() int { return 7 }ch := make(chan int)r, w := os.Pipe(fd)  // os.Pipe() returns two values_, y, _ := coord(p)  // coord() returns three values; only interested in y

概括:短變量聲明只需要指定變量標(biāo)識(shí)符以及對(duì)應(yīng)的值列表,編譯器會(huì)根據(jù)值的類型自動(dòng)推導(dǎo)出變量的類型。

Unlike regular variable declarations, a short variable declaration may redeclare variables provided they were originally declared earlier in the same block (or the parameter lists if the block is the function body) with the same type, and at least one of the non-blank variables is new. As a consequence, redeclaration can only appear in a multi-variable short declaration. Redeclaration does not introduce a new variable; it just assigns a new value to the original.

不同于常規(guī)變量聲明,在相同塊中且至少有一個(gè)新的非空白變量的短變量聲明中,可對(duì)原先聲明的變量以相同的類型重聲明。因此,重聲明只能出現(xiàn)在多變量的短聲明中。 重聲明沒(méi)有生成新的變量;它僅僅賦予新的值給原來(lái)的變量。

field1, offset := nextField(str, 0)field2, offset := nextField(str, offset)  // redeclares offseta, a := 1, 2                              // illegal: double declaration of a or no new variable if a was declared elsewhere

Short variable declarations may appear only inside functions. In some contexts such as the initializers for "if", "for", or "switch" statements, they can be used to declare local temporary variables


發(fā)表評(píng)論 共有條評(píng)論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 公安县| 鄂州市| 济源市| 独山县| 龙江县| 沙湾县| 万盛区| 阿拉善右旗| 桂东县| 牙克石市| 彭山县| 福海县| 马关县| 邵阳市| 佛山市| 克山县| 阜宁县| 五河县| 营口市| 全州县| 阳新县| 金阳县| 泰兴市| 兴国县| 保靖县| 丰顺县| 炎陵县| 宜宾县| 陇川县| 云南省| 南川市| 汝州市| 大悟县| 邵武市| 望江县| 麻城市| 阆中市| 乌鲁木齐县| 正定县| 德安县| 吉木乃县|