Advertisement
cwchen

[Go] Person struct w/ heterogenous fields.

Sep 19th, 2017
632
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Go 0.38 KB | None | 0 0
  1. package main
  2.  
  3. import (
  4.     "fmt"
  5. )
  6.  
  7. type Gender int
  8.  
  9. const (
  10.     Male Gender = iota
  11.     Female
  12. )
  13.  
  14. type Person struct {
  15.     name   string
  16.     gender Gender
  17.     age    uint
  18. }
  19.  
  20. func main() {
  21.     me := Person{gender: Male, age: 30, name: "Michael Chen"}
  22.  
  23.     fmt.Println(me.name)
  24.     fmt.Println(me.age)
  25.  
  26.     if me.gender == Male {
  27.         fmt.Println("Male")
  28.     } else {
  29.         fmt.Println("Female")
  30.     }
  31. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement