繁体   English   中英

未解决的参考:计数错误(Kotlin 函数)

[英]Unresolved reference: count error (Kotlin Function)

我正在学习 kotlin,我正在 kotlin 创建的 Playground 中玩耍。 在我进行演示练习时,我遇到了这些错误。 “未解决的引用:计数” “未解决的引用:计数”
我不明白为什么,因为我完全模仿了网站上示例中的演示。

fun generateAnswerMachine(countThreshold: Int): String {
val answerMachine = if (count < countThreshold) {
    "I have the answer."
} else {
    "The andswer eludes me"
}

return answerMachine 
}

val answerString = generateAnswerMachine(42)

还,

fun generateAnswerString(countThreshold: Int): String = if (count > countThreshold) {
    "I have the answer"
} else {
    "The answer eludes me"
}

在 function 中使用它之前,您必须定义count ,例如var count =...

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM