age:10,high:178,name:NewManage:10,high:178,name:NewManage:10,high:178,name:NewMan
age:10,high:178,name:NewManage:10,high:178,name:NewManage:10,high:178,name:NewMan
vba 股票交易接口,stringer接口定义如下:
此时的输出并不是我们想要的,所以这个用法不可行。
age:10,high:178,name:NewManage:10,high:178,name:NewManage:10,high:178,name:NewMan
##example2
package main
import (
'fmt'
)
type Power struct{
age int
high int
name vba 股票交易接口,string
}
//非指针
func (this Power) String() string {
return fmt.Sprintf('age:%d, high:%d, name:%s', this.age, this.high, this.name)
}
func main() {
var i Power = Power{age: 10, high: 178, name: 'NewMan'} //非指针变量
fmt.Printf('%s
', i)
fmt.Println(i)
fmt.Printf('%v', i)
}
##example1
package main
import (
'fmt'
)
type Power struct{
age int
high int
name string
}
//指针类型
func (this *Power) String() string {
return fmt.Sprintf('age:%d, high:%d, name:%s', this.age, this.high, this.name)
}
func main() {
var i *Power = &Power{age: 10, high: 178, name: 'NewMan'} //指针类型
fmt.Printf('%s
', i)
fmt.Println(i)
fmt.Printf('%v', i)
}
##example3
package main
import (
'fmt'
)
type Power struct{
age int
high int
name string
}
//非指针类型
func (this Power) String() string {
return fmt.Sprintf('age:%d, high:%d, name:%s', this.age, this.high, this.name)
}
func main() {
var i *Power = &Power{age: 10, high: 178, name: 'NewMan'}//指针类型
fmt.Printf('%s
', i)
fmt.Println(i)
fmt.Printf('%v', i)
}
下面通过一些例子加以说明。
##example4
package main
import (
'fmt'
)
type Power struct{
age int
high int
name string
}
//指针类型
func (this *Power) String() string {
return fmt.Sprintf('age:%d, high:%d, name:%s', this.age, this.high, this.name)
}
func main() {
var i Power = Power{age: 10, high: 178, name: 'NewMan'} //非指针
fmt.Printf('%s
', i)
fmt.Println(i)
fmt.Printf('%v', i)
}
文章为作者独立观点,不代表股票交易接口观点