技术宅,fat-man

增加语言的了解程度可以避免写出愚蠢的代码

导航

go : 结构

 

 1 package main
 2 
 3 import "fmt"
 4 
 5 type Employee struct{name string; age int} 
 6 //我在这里晕了一下,还认为是逗号分隔的
 7 
 8 
 9 func displayName(e Employee){
10 //函数参数里的变量不需要var,且{写在定义行里
11 
12     fmt.Printf(e.name + "\n")
13 }
14 
15 func main() {
16     var e1 Employee
17     e1.name = "shujun.li"
18     e1.age = 30
19     displayName(e1)
20 
21     e2 := Employee{"tan qiu ming", 30}
22     displayName(e2) 
23     // :=直接定义变量,这有点动态语言的意思,不过仍然需要指定类型(如果是自定义类型)
24 }

 

 

posted on 2013-05-13 17:30  codestyle  阅读(190)  评论(0)    收藏  举报