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;
}
Yes they are equal but I like to mark private variables as private, I think it improves reading.
also I use this common notation for private members, it's very useful :
private string _bar;
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)
I've been on the fence for a while about this. I used to argue for leaving it implicit, but now I think I'm tipped over towards making it explicit.
Reasons for leaving it implicit:
Reasons for making it explicit:
These latter points are basically the ones made by Eric Lippert when we discussed it a while ago.
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.
I think for readability it is always best to be explicit.
As a side, You may wish to have a look at a visual studio plug-in called Code Style Enforcer (http://joel.fjorden.se/static.php?page=CodeStyleEnforcer) which uses the dxCore extensions to provide real-time feedback on your codes adherence to coding standards (fully customisable).
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.