常用 go 命令

编译 / 执行代码

包相关





零值

自定义类型

函数接收者



Now, any variable of type "deck" now get access to the "print" method.
package main
import "fmt"
type deck []string
/*
func (this deck) print() {}
func (self deck) print() {}
While the code is technically valid and will compile, we don't ever reference a receiver value as 'this' or 'self'
Go avoids any mention of 'this' or 'self'
*/
func (d deck) print() {
for i, card := range d {
fmt.Println(i, card)
}
}
func main() {
cards := deck{"Ace of Spades", "Two of Spades"}
cards.print()
}
切片


字节切片


网友评论