Go 的结构体 是各个字段字段的类型的集合。这在组织数据时非常有用

Example:

package main

import "fmt"

type product struct{
name string
number int
} func main(){
//不指定字段。结构体赋值
fmt.Println(product{"phone", 10})
//注意字段名不加引号
fmt.Println(product{name:"abc", number: 30}) //省略字段默认为0
fmt.Println(product{name: "def"}) //使用点访问结构体属性。
s := product{name: "yhleng", number: 30}
fmt.Println(s.name, s.number) //&生成结构体指针,指针被自动解析引用
sptr := &s
fmt.Println(sptr.name) sptr.name = "xzdylyh"
fmt.Println(sptr.name)
}

Result:

$ go run example.go
{phone 10}
{abc 30}
{def 0}
yhleng 30
yhleng
xzdylyh

坐标: 上一个例子   下一个例子

最新文章

  1. python 基础
  2. Ubuntu下Nutch1.2的使用
  3. 前端二:CSS
  4. Windows Store App 插值动画
  5. R语言-神经网络包RSNNS
  6. Hive[4] 数据定义 HiveQL
  7. FZU 2016 summer train I. Approximating a Constant Range 单调队列
  8. 恭贺自己itpub和csdn双双获得专家博客称号
  9. [LeetCode]题解(python):129-Sum Root to Leaf Numbers
  10. 什么是Hadoop
  11. 自定义Git之搭建Git服务器
  12. Tomcat之URL查找的过程
  13. top命令用法详解
  14. 【java源码】解读HashTable类背后的实现细节
  15. Activit工作流学习例子
  16. bootstrap collapse 无法收回
  17. emoji & click copy
  18. Arrow functions and the ‘this’ keyword
  19. MFC-Dialog各函数的执行顺序
  20. [PHP] constant variable

热门文章

  1. 02.自定义banner、全局配置文件、@Value获取自定义配置、@ConfigurationProperties、profiles配置
  2. wait与sleep区别?
  3. GSL+DevC++使用
  4. 转载:Eclipse下的java工程目录
  5. ubuntu软件源变更阿里源和arm板子变更国内源
  6. flask01
  7. springMVC使用map接收入参 + mybatis使用map 传入查询参数
  8. 获取数组NSArray元素的className
  9. Bugku | Easy_Re
  10. JDK1.8 动态代理机制及源码解析