中級 › is inaccessible due to its protection level の原因と直し方 › パターン5
is inaccessible due to its protection level の原因と直し方
privateなメンバーにクラスの外部からアクセスしようとすると出るコンパイルエラーです。
1 class User { 2 private string password = "hunter2"; 3 public string username = "al"; 4 } 5 class Program { 6 static void Main(string[] args) { 7 User u = new User(); 8 System.Console.WriteLine(u.________); ^ 9 } 10 }
Program.cs(8,36): error CS0122: 'User.password' is inaccessible due to its protection level
空欄を埋めてビルドを通す
機密性の高いフィールドはprivateにして外部から直接読めないようにします。
次の問題