File tree Expand file tree Collapse file tree 1 file changed +70
-0
lines changed Expand file tree Collapse file tree 1 file changed +70
-0
lines changed Original file line number Diff line number Diff line change @@ -2021,6 +2021,76 @@ func main() {
20212021
20222022< /details>
20232023
2024+ # # 结构体
2025+
2026+ < details>
2027+ < summary> 结构体字段< /summary>
2028+
2029+ 结构体字段使用点号来访问。
2030+
2031+ ` ` ` go
2032+ package main
2033+ import " fmt"
2034+ type Vertex struct {
2035+ X int
2036+ Y int
2037+ }
2038+ func main () {
2039+ v := Vertex{1, 2}
2040+ v.X = 4
2041+ fmt.Println(v.X)
2042+ }
2043+ ` ` `
2044+
2045+ < /details>
2046+
2047+ < details>
2048+ < summary> 结构体指针< /summary>
2049+
2050+ 结构体字段使用点号来访问。
2051+
2052+ ` ` ` go
2053+ package main
2054+ import " fmt"
2055+ type Vertex struct {
2056+ X int
2057+ Y int
2058+ }
2059+ func main () {
2060+ v := Vertex{1, 2}
2061+ p := & v
2062+ p.X = 1e9
2063+ fmt.Println(v)
2064+ }
2065+
2066+ ` ` `
2067+
2068+ < /details>
2069+
2070+ < details>
2071+ < summary> 结构体文法< /summary>
2072+
2073+ > 结构体文法表示通过结构体字段的值作为列表来新分配一个结构体。
2074+ > 使用 Name: 语法可以仅列出部分字段。(字段名的顺序无关。)
2075+ > 特殊的前缀 & 返回一个指向结构体的指针。
2076+
2077+ ` ` ` go
2078+ package main
2079+ import " fmt"
2080+ type Vertex struct {
2081+ X int
2082+ Y int
2083+ }
2084+ func main () {
2085+ v := Vertex{1, 2}
2086+ p := & v
2087+ p.X = 1e9
2088+ fmt.Println(v)
2089+ }
2090+ ` ` `
2091+
2092+ < /details>
2093+
20242094# # 资源导航
20252095
20262096< details>
You can’t perform that action at this time.
0 commit comments