Advertisement
arxeiss

Bc Go Example

Apr 29th, 2016
157
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Go 0.53 KB | None | 0 0
  1. import "fmt"
  2.  
  3. // Example of new variable by explicit and implicit type
  4. var a int
  5. b := "This variable will be string"
  6.  
  7. // New data type as struct
  8. type Person struct {
  9.     Name  string
  10.     Age   int
  11.     IsMan bool
  12. }
  13. // Function without parametrs, returning string which
  14. // belongs to Person struct
  15. func (p *Person) ReturnAsSentece() string {
  16.     return fmt.Sprintf("Person %v is %d years old", p.Name, p.Age)
  17. }
  18. // Create new variable as pointer to struct Person
  19. person := &Person{"Pavel", 23, true}
  20. fmt.Println(person.ReturnAsSentence())
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement