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

前端 未结 10 1678
星月不相逢
星月不相逢 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:27

    Don't make people guess, don't let them make false assumptions, and don't think fewer characters in any way equates to clarity.

    There's no good reason not to make this explicit, and imho it's a mistake for C# to support it (especially if they're willing to do what they did to switch statements for the same reason)

提交回复
热议问题