快速教程----函数中的“条件”是什么意思?

2024-03-01

I know that in the first line, we can use lessThanTen(number: Int) to replace (int), and contidion means a label, but in the third line: * why dont we use if condition : (item) to replace if condition(item), since condition is a label. enter image description here


如果您查看该方法签名,则条件是您在该方法上收到的方法:

condition: (int) -> Bool

这意味着您正在接收一个可以使用 Int 类型参数调用的条件,并将返回一个 bool。任何地方,内部:

hasAnyMatches 

你将能够使用

condition(anyInt)

现在,如果您查看方法调用者:

hasAnyMatches(list: numbers, condition: lessThanTen)

所以,你是说“hasAnyMatches”的“条件”将是“lessThanTen”。这意味着在你的

if condition(item)

真正发生的事情是:

if lessThanTen(item)

我希望它能说得更清楚!

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

快速教程----函数中的“条件”是什么意思? 的相关文章

随机推荐