2014-07-23 129 views
12

使用在有条件的价值假设中去,我们有一个函数返回两个参数Golang:从函数返回多个参数

func squareAndCube(int side) (square int, cube int) { 
    square = side * side 
    cube = square * side 
    return 
} 

然后你想使用该功能的第一(第二)值的条件:

square, _ := squareAndCube(n) 
if square > m { 
    ... 
} 

然而,我们可以做一个行头两行,如果我们不需要价值广场其他地方使用?例如。

if squareAndCube(n).First() > m { 
    ... 
} 

回答