Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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;
}

I guess these two declarations are equal.

So my question is: what for should I mark private variables as private if they already are private?

like image 347
abatishchev Avatar asked Nov 26 '22 20:11

abatishchev


1 Answers

Now; fields should pretty-much always be private anyway, so it is an edge case whether you should bother.

For the wider subject, I remember a comment by Eric Lippert - essentially saying that given a method / class / whatever:

void Foo() {}
class Bar {}

Then it isn't clear whether they are private/internal deliberately, or whether the developer has thought about it, and decided that they should be private/internal/whatever. So his suggestion was: tell the reader that you are doing things deliberately instead of by accident - make it explicit.

like image 65
Marc Gravell Avatar answered Dec 10 '22 21:12

Marc Gravell