<kbd id="afajh"><form id="afajh"></form></kbd>
<strong id="afajh"><dl id="afajh"></dl></strong>
    <del id="afajh"><form id="afajh"></form></del>
        1. <th id="afajh"><progress id="afajh"></progress></th>
          <b id="afajh"><abbr id="afajh"></abbr></b>
          <th id="afajh"><progress id="afajh"></progress></th>

          Go語(yǔ)言入門(4) - 地圖 Get started with the Go language

          共 1401字,需瀏覽 3分鐘

           ·

          2022-11-22 11:22

          今日單詞  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.


          package main

          import (
          "fmt"
          "math"
          )

          type
          Vertex struct {
          X
          , Y float64
          }

          func
          (v *Vertex) Abs() float64 {
          return math.Sqrt(v.X*v.X + v.Y*v.Y)
          }

          func main
          () {
          v
          := &Vertex{3, 4}
          fmt
          .Println(v.Abs())
          }


          瀏覽 60
          點(diǎn)贊
          評(píng)論
          收藏
          分享

          手機(jī)掃一掃分享

          分享
          舉報(bào)
          評(píng)論
          圖片
          表情
          推薦
          點(diǎn)贊
          評(píng)論
          收藏
          分享

          手機(jī)掃一掃分享

          分享
          舉報(bào)
          <kbd id="afajh"><form id="afajh"></form></kbd>
          <strong id="afajh"><dl id="afajh"></dl></strong>
            <del id="afajh"><form id="afajh"></form></del>
                1. <th id="afajh"><progress id="afajh"></progress></th>
                  <b id="afajh"><abbr id="afajh"></abbr></b>
                  <th id="afajh"><progress id="afajh"></progress></th>
                  国产丝袜人妖CD露出 | 91中文字幕在线观看 | 日韩一区二区三区中文高清电影 | 91无码影院 | 97大香蕉在线视频 |