GO语言中的Lambda表达式

GO语言中的Lambda表达式,go,lambda,Go,Lambda,在C#中,我们可以使用lambda表达式编写如下内容,我们如何在GO语言中实现这一点?基本上,我正在寻找一种能力,可以在函数前面传递一些参数,然后在函数可用时传递一些参数 myFunc = (x) => Test(123, x) // Method Test is declared below. myFunc("hello") // this calls method Test with params int 123 & string "hello" where int was p

在C#中,我们可以使用lambda表达式编写如下内容,我们如何在GO语言中实现这一点?基本上,我正在寻找一种能力,可以在函数前面传递一些参数,然后在函数可用时传递一些参数

myFunc = (x) => Test(123, x) // Method Test is declared below.
myFunc("hello") // this calls method Test with params int 123 & string "hello" where int was passed upfront whereas string was passed when Test is actually called on this line

void Test(int n, string x)
{
    // ...
}
试试这个:

func Test(n int, x string) {
    fmt.Println(n, x)
}
func main() {
    myFunc := func(x string) { Test(123, x) }
    myFunc("hello")
}

我想这个问题已经得到了回答。