請考慮以下(C#)代碼。被傳遞給ConvolutedRand()的lambda被稱爲「關閉」了名爲format的變量。用什麼術語來描述在MyMethod()中如何使用變量random?「封閉」這個詞的相反之處是什麼?
void MyMethod
{
int random;
string format = "The number {0} inside the lambda scope";
ConvolutedRand(x =>
{
Console.WriteLine(format, x);
random = x;
});
Console.WriteLine("The number is {0} outside the lambda scope", random);
}
void ConvolutedRand(Action<int> action)
{
int random = new Random.Next();
action(random);
}
我可以告訴你有資格根據你的用戶圖標來回答這個問題。 – anthony 2010-09-30 07:34:11