Why are my privates accessible?

后端 未结 5 844
温柔的废话
温柔的废话 2021-01-19 05:47

I have the following code:

public class PersonInitializer
{
    private Person _person;

    public static Person LoadFromFile(string path)
    {
        Per         


        
5条回答
  •  执笔经年
    2021-01-19 06:19

    From the documentation:

    Private members are accessible only within the body of the class or the struct in which they are declared.

    Since LoadFromFile is within the body of the class where _person is declared, it has access to it. There's nothing you can do about that, since

    Private access is the least permissive access level.

提交回复
热议问题