这两个 Golang 函数返回的区别是什么?

huangapple go评论80阅读模式
英文:

What the different between those two Golang function return

问题

这两个 Golang 函数有什么不同,它们彼此相同吗?

func foo1() (ret string) {
    ret = "hi there"
    return
}

func foo2() string {
    ret := "hi there"
    return ret
}

哪个更好?

英文:

What the different between those two Golang functions, are they the same with each other?

func foo1() (ret string) {
    ret = "hi there"
    return
}

func foo2() string {
	ret := "hi there"
	return ret
}

which is better?

答案1

得分: 3

这两个函数是相同的:https://go.dev/play/p/_6KT5thL2Sj

英文:

These two functions are identical: https://go.dev/play/p/_6KT5thL2Sj

huangapple
  • 本文由 发表于 2022年1月6日 08:55:55
  • 转载请务必保留本文链接:https://go.coder-hub.com/70601326.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定