[Solved] C# – Unable to declare a private variable in constructor


However, I still don’t understand why I’m unable to declare and initialize a private variable inside the constructor while declaring the variable without a public/private modifier works just fine.

This is just the way the C# spec is written. Class-level instance variables (public or private) cannot be declared inside class methods or constructors.

Check out the MSDN documentation for discussion around C# classes.

1

solved C# – Unable to declare a private variable in constructor