专注于 JetBrains IDEA 全家桶,永久激活,教程
持续更新 PyCharm,IDEA,WebStorm,PhpStorm,DataGrip,RubyMine,CLion,AppCode 永久激活教程

Functions continued----继续Go的Function探索

#

When two or more consecutive named function parameters share a type, you can omit the type from all but the last.
In this example, we shortened
x int, y int
to
x, y int

代码

package main
import "fmt"

func add(x, y int) int {
    return x + y
}

func main() {
    fmt.Println(add(42, 13))
}

翻译

当你的函数(function)有多个参数,但是这几个参数的类型都一样的时候,你只需要在最后一个写上就行了
在这个例子当中 
x int,y int
你可以这么写:
x,y int(这意思就是说x和y都是int类型)

总结

这个是Go提供的一个便利,但是感觉这么写会不会不太好看,后面看GO推荐的style吧
总结起来就是这么个事情

func argumentOmit(number int,count int,userName string,password string,pageSize int,pageNumber int,total int){
    ........具体内容
}

也可以写成:

func argumentOmit(number,count int,userName,password string,pageSize,pageNumber,total int){
    ........具体内容
}

注意只能修改连续,不连续的不能合并简写变量类型

文章永久链接:https://tech.souyunku.com/44585

未经允许不得转载:搜云库技术团队 » Functions continued----继续Go的Function探索

JetBrains 全家桶,激活、破解、教程

提供 JetBrains 全家桶激活码、注册码、破解补丁下载及详细激活教程,支持 IntelliJ IDEA、PyCharm、WebStorm 等工具的永久激活。无论是破解教程,还是最新激活码,均可免费获得,帮助开发者解决常见激活问题,确保轻松破解并快速使用 JetBrains 软件。获取免费的破解补丁和激活码,快速解决激活难题,全面覆盖 2024/2025 版本!

联系我们联系我们