class MyClass
{
**private** delegate void MyDelegate(); //error: MyDelegate is less accessible than property Del
private MyDelegate del;
public MyDelegate Del
{
get { return this.del; }
set { this.del = value; }
}
}
更改为公共(public)修复程序,但我想知道更详细的原因。
最佳答案
如果将 MyDelegate 定义为私有(private)类型,MyClass 的使用者如何知道 Del
的类型?这就像您定义一个私有(private)类并尝试在公共(public)属性中使用该私有(private)类
关于c# - 为什么委托(delegate)在用作属性(property)时必须公开?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11322732/