Created
October 15, 2019 10:23
-
-
Save fpagyu/aeb772f56b4ac0ccbe59e976f0fc8d6c to your computer and use it in GitHub Desktop.
Go三元表达式
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func If(condition bool, trueVal, falseVal interface{}) interface{} { | |
if condition { | |
return trueVal | |
} | |
return falseVal | |
} | |
a, b := 2, 3 | |
max := If(a > b, a, b).(int) | |
println(max) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment