Go语言学习之method(The way to go)

编程入门 行业动态 更新时间:2024-10-15 08:23:28

Go<a href=https://www.elefans.com/category/jswz/34/1770116.html style=语言学习之method(The way to go)"/>

Go语言学习之method(The way to go)

生命不止,继续go go go !

在golang的世界中,一定要区分 方法和函数

Go中没有类的概念,但是我们可以在一些类型上定义一些方法,也就是所谓的方法,跟函数不同。

通过func关键字声明方法

type Vertex struct {X, Y float64
}func (v Vertex) Abs() float64 {return math.Sqrt(v.X*v.X + v.Y*v.Y)
}
type X struct{}func (x *X) test(){println("hi!", x)
}

方法的使用

更多推荐

Go语言学习之method(The way to go)

本文发布于:2024-02-27 17:22:06,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1707525.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:语言   method

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!