Swift函数_外部参数名,

//1________________

 /**

 *没使用外部参数名的函数

 */

func inputScore(name:String,score1:Int,score2:Int)

{

}

/**

 * 包含外部参数名的函数

 */

func inputScore(studentName name:String,mathScore score1:Int,englishScore score2:Int)

{

}

//使用外部参数名的函数

inputScore(studentName:"peter",mathScore:99,englistScore:83);

//外部参数名的优点 可以在不看函数内容的情况下 直接了解参数的作用。  

//2__________________#外部参数名简写 在swift2.0以后移除

 

//外部参数名的一种简写方式__"#" 

func changeName(#name:String){//加#是简写name作为外部参数名

 

    name = "Hello"

 

    println(name)

 

}

 

var userName= "泥嚎"

 

println(userName)

 

changeName(name:userName) //函数定义时,name前加#作为函数内的局部变量的同时也作为外部参数名.

 

 

posted on 2016-05-08 12:45  Sweet小马  阅读(424)  评论(0编辑  收藏  举报

导航