Inaccessible due to its protection level?

前端 未结 5 591
臣服心动
臣服心动 2020-12-21 05:39

I\'m still quite new to coding in general, and while this simple program is only meant to be a test to learn how constructors work, I\'d still like to know why I\'m getting

5条回答
  •  孤城傲影
    2020-12-21 06:12

    If you want to access your integers a, b, and c from outside of the class they are instantiated in, you have to declare them as public. However a cleaner option is to use a property, such as:

    public int A {get; set;}
    public int B {get; set}
    public int C {get; set;}
    

    This sets up you up to potentially limit write access from outside classes, while still leaving the the properties open for reading, such as:

    public int A {get; private set;}
    public int B {get; private set}
    public int C {get; private set;}
    

提交回复
热议问题