Advertisement
fcamuso

Un assaggio di Go - Video 7

Jul 4th, 2025
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.18 KB | None | 0 0
  1. package main
  2.  
  3. import (
  4.     "errors"
  5.     "fmt"
  6. )
  7.  
  8. type Indirizzo struct {
  9.     Citta string
  10.     CAP   string
  11. }
  12.  
  13. type Persona struct {
  14.     Nome    string
  15.     Cognome string
  16.     Eta     int
  17.  
  18.     Indirizzo
  19.     //codice string
  20. }
  21.  
  22. func (p *Persona) Invecchia() {
  23.     p.Eta++
  24.     //((*p).Eta)++
  25. }
  26.  
  27. func main() {
  28.  
  29.     p1 := Persona{}
  30.  
  31.     var p2 = Persona{
  32.         Nome:    "Mario",
  33.         Cognome: "Rossi",
  34.         Eta:     30,
  35.     }
  36.  
  37.     p2.Invecchia() //Invecchia(p2)
  38.  
  39.     fmt.Println(p1, p2)
  40.  
  41.     p2.Citta = "Milano";
  42.  
  43.     // map1 := make(map[string]int)
  44.     // map1["Tevere"] = 406
  45.  
  46.     // map2 := map[string]float32{
  47.     //  "standard":     69.99,
  48.     //  "deluxe":       89,
  49.     //  "super deluxe": 129,
  50.     // }
  51.     // map2["stra super deluxe"] = 200
  52.  
  53.     // //ha la deluxe?
  54.     // costo, esiste := map2["deluxe"]
  55.  
  56.     // if !esiste {
  57.     //  fmt.Println("Edizione non disponibile")
  58.     // } else {
  59.     //  fmt.Println("Costo: ", costo)
  60.     // }
  61.  
  62.     // delete(map2, "deluxe")
  63.     // costo, esiste = map2["deluxe"]
  64.  
  65.     // if !esiste {
  66.     //  fmt.Println("Edizione non disponibile")
  67.     // } else {
  68.     //  fmt.Println("Costo: ", costo)
  69.     // }
  70.  
  71.     // //iteriamo sulla mappa
  72.     // for key, value := range map2 {
  73.     //  fmt.Println(key, " Costo: ", value)
  74.     // }
  75.  
  76. }
  77.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement