GO学习笔记(结构体)

go 可以像c 语言一样使用struct 定义结构体

go 结构体定义和使用

type cat struct {
     // 结构体内容
     Name string
     Age  int
     Color string
}

方式一通过 对象.属性 来赋值

var c person
c.Name = “楼楼”
c.Age = 12
c.Color = “白色”

方式二通过 键值对 来赋值

c := cat{name: “楼楼”, age: 12, color: “白色”}

方式三通过 属性顺序 来赋值

c := cat{“楼楼”, 12, “白色”}

以上就是go结构体的简单定义和使用。更多的使用教程请参考GitHub这个教程:https://github.com/astaxie/build-web-application-with-golang/blob/master/zh/02.4.md

猜你喜欢

转载自blog.csdn.net/lucky404/article/details/79997769