Compiler Error CS0052
可访问性不一致: 字段类型“type”比字段“field”的访问性低
字段类型的可访问性不能比字段本身的可访问性低,因为所有的公共构造都必须返回公共的可访问对象。
下面的示例生成 CS0052:
// CS0052.cs
public class MyClass2
{
// The following line causes an error because the field, M, is declared
// as public, but the type, MyClass, is private. Therefore the type is
// less accessible than the field.
public MyClass M; // CS0052
private class MyClass
{
}
// One way to resolve the error is to change the accessibility of the type
// to public.
//public class MyClass
// Another solution is to change the accessibility of the field to private.
// private MyClass M;
}
public class MainClass
{
public static void Main()
{
}
}