为什么这段代码不能编译?
Why this piece of code does not compile?
delegate int xxx(bool x = true);
xxx test = f;
int f()
{
return 4;
}
可选参数用于调用端 - 而不是像单方法接口实现那样有效.例如,这个应该编译:
Optional parameters are for use on the calling side - not on what is effectively like a single-method-interface implementation. So for example, this should compile:
delegate void SimpleDelegate(bool x = true);
static void Main()
{
SimpleDelegate x = Foo;
x(); // Will print "True"
}
static void Foo(bool y)
{
Console.WriteLine(y);
}
这篇关于代表上的可选参数无法正常工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!