第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問(wèn)題,去搜搜看,總會(huì)有你想問(wèn)的

如何在結(jié)構(gòu)中添加切片數(shù)組

如何在結(jié)構(gòu)中添加切片數(shù)組

Go
寶慕林4294392 2021-12-07 19:30:37
我希望在我在 Go 中創(chuàng)建的結(jié)構(gòu)內(nèi)為字符串變量添加一個(gè)數(shù)組。type Recipes struct { //Struct for recipe information    name             string    prepTime         int    cookTime         int    recipeIngredient string    recipeID         int    recipeYield      int}它被稱為Recipe1.name = "BBQ Pulled Chicken"Recipe1.prepTime = 25Recipe1.cookTime = 5Recipe1.recipeIngredient = "1 8-ounce can reduced-sodium tomato sauce, two"Recipe1.recipeID = 1Recipe1.recipeYield = 8recipeIngredient 將有多種成分,所以它不能是一個(gè)字符串。我想在 recipeIngredient 中有多個(gè)數(shù)組/切片元素。任何人都知道我將如何做到這一點(diǎn)?
查看完整描述

1 回答

?
汪汪一只貓

TA貢獻(xiàn)1898條經(jīng)驗(yàn) 獲得超8個(gè)贊

使用一片string. 例如,


package main


import "fmt"


type Recipe struct {

    Name        string

    PrepTime    int

    CookTime    int

    Ingredients []string

    ID          int

    Yield       int

}


func main() {

    var recipe Recipe

    recipe.Name = "BBQ Pulled Chicken"

    recipe.PrepTime = 25

    recipe.CookTime = 5

    recipe.Ingredients = append(recipe.Ingredients,

        "1 8-ounce can reduced-sodium tomato sauce",

    )

    recipe.Ingredients = append(recipe.Ingredients,

        "1/2 medium onion, grated ",

    )

    recipe.ID = 1

    recipe.Yield = 8

    fmt.Println(recipe)

    fmt.Printf("Ingredients: %q\n", recipe.Ingredients)

}

輸出:


{BBQ Pulled Chicken 25 5 [1 8-ounce can reduced-sodium tomato sauce 1/2 medium onion, grated ] 1 8}

Ingredients: ["1 8-ounce can reduced-sodium tomato sauce" "1/2 medium onion, grated "]


查看完整回答
反對(duì) 回復(fù) 2021-12-07
  • 1 回答
  • 0 關(guān)注
  • 212 瀏覽
慕課專欄
更多

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)