函数和闭包剖析.pptVIP

  • 0
  • 0
  • 约5.98千字
  • 约 22页
  • 2017-01-15 发布于湖北
  • 举报
函数和闭包剖析

注意:传递一个可变参数的参数的值时,函数体中是以提供适当类型的数组的形式存在。例如,一个可变参数的名称为numbers和类型为Double...在函数体内就作为名为numbers类型为Double[]的常量数组。 func arithmeticMean(numbers: Double...) - Double { var total: Double = 0 for number in numbers { total += number } return total / Double(numbers.count) } arithmeticMean(1, 2, 3, 4, 5) // returns 3.0, which is the arithmetic mean of these five numbers arithmeticMean(3, 8, 19) // returns 10.0, which is the arithmetic mean of these three numbers 提示:函数可以最多有一个可变参数的参数,而且它必须出现在参数列表的最后以避免多参数函 数调用时出现歧义。如果函数有一个或多个参数使用默认值,并且还具有可变参数,将可变参数放在列表的 最末尾的所有默认值的参数之后。 函数参数的默认值都是常量。 通过

文档评论(0)

1亿VIP精品文档

相关文档