Go编程笔记(32)

前端之家收集整理的这篇文章主要介绍了Go编程笔记(32)前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
packagemain

import(
	"fmt"
)

typeUserstruct{
	Idint
	Namestring
}

typeManagerstruct{
	User
	Groupstring
}

func(u*User)Test(){
	fmt.Println("UserTest:",u.Id,u.Name)
}

func(uUser)ToString()string{
	returnfmt.Sprintf("UserToString:[%d]%s",u.Name)
}

func(mManager)Test(){
	fmt.Println("ManagerTest:",m.Id,m.Name)
}

funcmain(){
	m:=&Manager{User{1,"Tom"},"IT"}
	m.Test()
	fmt.Println(m.ToString())
}

输出结果:

ManagerTest:1Tom
UserToString:[1]Tom
原文链接:https://www.f2er.com/go/191138.html

猜你在找的Go相关文章