golang语言中struct的初始化方式
发布时间:2020-12-16 18:46:02 所属栏目:大数据 来源:网络整理
导读:// 先定义结构体type Rect struct {width intheight int}// 再初始化结构体rect1 := new(Rect)rect2 := Rect{}rect3 := Rect{10,20}rect4 := Rect{width:10,height:20}// 定义 + 初始化同时进行rect5 := struct{width int,height int}{10,20}
// 先定义结构体 type Rect struct { width int height int } // 再初始化结构体 rect1 := new(Rect) rect2 := &Rect{} rect3 := &Rect{10,20} rect4 := &Rect{width:10,height:20} // 定义 + 初始化同时进行 rect5 := &struct{width int,height int}{10,20} (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |