What for should I mark private variables as private if they already are?

前端 未结 10 1796
星月不相逢
星月不相逢 2021-01-06 18:43

As far as I know, in C# all fields are private for default, if not marked otherwise.

class Foo
{
  private string bar;
}

class Foo
{
  string bar;
}
         


        
10条回答
  •  無奈伤痛
    2021-01-06 19:30

    If you were switching between Java and C# on a regular basis I imagine it would be fairly important to specify the access modifier explicity. For example in Java

    void myMethod()
    {
    
    }
    

    any class in your package has access to that method. In C# it's obviously private to the class and inner classes.

提交回复
热议问题