2017-12-29 8 views
-1

C#에서는 람다 식을 사용하여 다음과 같이 작성할 수 있습니다. 어떻게 GO 언어로이 작업을 수행 할 수 있습니까? 기본적으로, 일부 매개 변수를 함수 앞에 전달하고 나중에 사용할 수있는 매개 변수를 전달할 수있는 기능을 찾고 있습니다.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) 
{ 
    // ... 
} 
+3

나는이 질문은 [여기] (답 있다고 생각 https://stackoverflow.com/questions/11766320/does-go-have- 람다 식 - 또는 - 비슷한 - 비슷한). –

답변

3

이 시도 :

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

playground