“Ketik sakelar golang” Kode Jawaban

Ketik sakelar 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

sakelar golang

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

sakelar golang

	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

Jenis golang sakelar

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

Beralih di Golang

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

  case "saturday":
    rest()

  default:
    work()
}
Harendra

Jawaban yang mirip dengan “Ketik sakelar golang”

Pertanyaan yang mirip dengan “Ketik sakelar golang”

Lebih banyak jawaban terkait untuk “Ketik sakelar golang” di Go

Jelajahi jawaban kode populer menurut bahasa

Jelajahi bahasa kode lainnya