1 回答
TA贡献1898条经验 获得超8个赞
使用一片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 "]
- 1 回答
- 0 关注
- 181 浏览
添加回答
举报