go学习(六)——结构体初始化

xiaoxiao2021-02-28  105

package main import ( "fmt" ) type Info struct { Cpu string Mem string Disk string } type Product struct { Info Id string Name string } func main() { p1 := Product{Info:Info{"4","8","20"}, Id:"1001", Name:"VFW"} //方法一 p2 := Product{Info{"4","8","20"}, "1001", "VFW"} //方法二 p3 := Product{Info:Info{Cpu:"4",Mem:"8",Disk:"20"}, Id:"1001", Name:"VFW"} //方法三 fmt.Println(p1) fmt.Println(p2) fmt.Println(p3) }
转载请注明原文地址: https://www.6miu.com/read-38885.html

最新回复(0)