我想把Two
喂给function
。当函数接收到Two
作为数据时,应该将success
打印到控制台。但这似乎不是正确的方法。
错误:Conditions must have a static type of 'bool'. Try changing the condition.
enum ButtonList {One, Two, Three}
调用函数
testFunc(ButtonList.Two)),
testFunc( ButtonList type) {
if (type = ButtonList.Two ){print('sucess ')};
}
应该是:
testFunc(ButtonList type) {
if (type == ButtonList.Two) {
print('sucess ')
};
}
=
(给变量赋值)和==
(相等比较)之间有很大的区别。if
需要一个条件(==
),而不是赋值操作(=
)。
如果您想用=赋值,请使用==代替