Golang 学习笔记

Golang:基础图解

2017-12-05  本文已影响4人  与蟒唯舞
常用 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()
}
切片
字节切片
上一篇 下一篇

猜你喜欢

热点阅读