英語で読む

次の方法で共有


コンパイラ エラー CS0052

アクセシビリティに一貫性がありません。フィールドの型 'type' のアクセシビリティはフィールド 'field' よりも低く設定されています

すべての public コンストラクトで一般公開オブジェクトを返す必要があるため、フィールドの型のアクセシビリティをフィールド自体のアクセシビリティより低くすることはできません。

次の例では 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()
    {
    }
}

関連項目