代码示例:
package main
import "fmt"
func main() {
a := []int{1, 2}
b := []int{3, 4, 5}
a, b = b, a
fmt.Println(`a:`, a)
fmt.Println(`b:`, b)
}
package main
import "fmt"
func main() {
a := []int{1, 2}
b := []int{3, 4, 5}
a, b = b, a
fmt.Println(`a:`, a)
fmt.Println(`b:`, b)
}
本文标题:Go语言:最简单的方法交换两个值(支持任意类型)
本文链接:https://www.haomeiwen.com/subject/dahwpctx.html
网友评论