中級 › is inaccessible due to its protection level の原因と直し方 › パターン1
is inaccessible due to its protection level の原因と直し方
privateなメンバーにクラスの外部からアクセスしようとすると出るコンパイルエラーです。
1 class Box { 2 private int secret = 42; 3 public int visible = 100; 4 } 5 class Program { 6 static void Main(string[] args) { 7 Box b = new Box(); 8 System.Console.WriteLine(b._______); ^ 9 } 10 }
Program.cs(8,36): error CS0122: 'Box.secret' is inaccessible due to its protection level
空欄を埋めてビルドを通す
privateなメンバーはそのクラスの内部からしかアクセスできません。外部から使いたいならpublicにするかプロパティ経由にします。
次の問題