Değişkenin tipini when() metodu ile kontrol etme

Categories:
1 dakikadan az
Bu yazıda, veri tipi ile When() kullanımına bir örnek görebilirsiniz. Veri türü, çalıştırılacak kodu belirleyecektir.
val x : Any = 12.75
when(x){
is Int -> println("$x is an Integer")
is Double -> println("$x is a Double")
is String -> println("$x is a String")
else -> println("$x is not Int,Double or String")
}

Geribildirim
Bu sayfa yararlı oldu mu?
Glad to hear it! Please tell us how we can improve.
Sorry to hear that. Please tell us how we can improve.