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?
Up to you. Do what's best for readability or makes sense in your case. I mark them as private just to make it clear though.
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:
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.
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 :