Code Fix

中級 › is inaccessible due to its protection level の原因と直し方 › パターン4

is inaccessible due to its protection level の原因と直し方

privateなメンバーにクラスの外部からアクセスしようとすると出るコンパイルエラーです。

 1  class Vault {
 2      private int code = 1234;
 3      public string label = "safe";
 4  }
 5  class Program {
 6      static void Main(string[] args) {
 7          Vault v = new Vault();
 8          System.Console.WriteLine(v._____);
                                         ^
 9      }
10  }
Program.cs(8,36): error CS0122: 'Vault.code' is inaccessible due to its protection level

空欄を埋めてビルドを通す

広告
広告スロット(未設定)

is inaccessible due to its protection level の原因と直し方

このエラーの解説と類題をまとめて見る →

広告
広告スロット(未設定)