“Typ Switch Golang” Code-Antworten

Typ Switch Golang

var x interface{} = "foo"

switch v := x.(type) {
case nil:
    fmt.Println("x is nil")            // here v has type interface{}
case int: 
    fmt.Println("x is", v)             // here v has type int
case bool, string:
    fmt.Println("x is bool or string") // here v has type interface{}
default:
    fmt.Println("type unknown")        // here v has type interface{}
}
Difficult Dotterel

Golang -Schalter

func main() {
	i := 2
    switch i {
    case 1:
        fmt.Println("one")
    case 2:
        fmt.Println("two")
    case 3:
        fmt.Println("three")
    }
}
Radu Cuziac

Golang -Schalter

	package main 
    
    my_number := 2
    fmt.Print("Write ", my_number, " as ")
    
    switch my_number {
      case 1:
          fmt.Println("one")
      case 2:
          fmt.Println("two")
      case 3:
          fmt.Println("three")
      default :
          // default case 
    }

Long Lemur

Schaltertyp Golang

var value interface{} = "Hello Grepper"
switch vale.(type){
	case string:
    	fmt.Println("It is a string")
    case int:
    	fmt.Println("It is a int")
    default:
    	fmt.Println("Not sure")
}
Zany Zebra

Golang einschalten

switch day {
  case "sunday":
    // cases don't "fall through" by default!
    fallthrough

  case "saturday":
    rest()

  default:
    work()
}
Harendra

Ähnliche Antworten wie “Typ Switch Golang”

Fragen ähnlich wie “Typ Switch Golang”

Weitere verwandte Antworten zu “Typ Switch Golang” auf Go

Durchsuchen Sie beliebte Code-Antworten nach Sprache

Durchsuchen Sie andere Codesprachen