Go語(yǔ)言入門(4) - 地圖 Get started with the Go language
今日單詞 Words for today
lack 缺少
struct 結(jié)構(gòu)
sequence 結(jié)構(gòu)
method 方法
declaration 聲明
identifier 識(shí)別符
associate 聯(lián)系
uppercase 大寫字母
lowercase 小寫字母
addressable 可尋趾的
Structs and methods
結(jié)構(gòu)與方法
The Go language lacks classes but has a struct, which is a sequence of named elements, which are called fields. Each field has a name and a type. A method is a function with a receiver. A method declaration binds an identifier (the method name) to a method and associates the method with the receiver's base type.
GO語(yǔ)言沒(méi)有類但是有結(jié)構(gòu),它是一個(gè)命名連續(xù)的序列,它被稱作fields。每一個(gè)field都有一個(gè)名字和類型。方法是一個(gè)帶有接收器的函數(shù)。聲明一個(gè)識(shí)別符(方法名)綁定到方法,并將方法與接收者的基本類型相關(guān)聯(lián)。
In this example, we declare a Vertex struct to contain two floating point fields, X and Y, and a method, Abs. Fields that begin with uppercase letters are public; fields that begin with lowercase letters are private. Fields and methods are addressable through the dot notation (.) and ampersands (&) signify pointers, as in C. This program prints 5.
在此示例中,我們聲明 一個(gè)Vertex struct包含兩個(gè)浮點(diǎn)fields X 和 Y 以及一個(gè)方法Abs。以大寫字母開(kāi)頭的字段是公開(kāi)的;以小寫字母開(kāi)頭的字段是私有的。字段和方法可以通過(guò)點(diǎn)符號(hào) ( .)進(jìn)行尋址,和號(hào) ( &) 表示指針,就像在 C 中一樣。這個(gè)程序打印5.
