I've heard various programmers suggest not including the word "private" in declarations, method signatures, etc. as private is the default scope when not specified. It can make for cleaner code but I'm interested in what the opinions are on whether you use the "private" scope on your variables, methods, etc. Tools like CodeRush that generate code for you include the word "private" so I'm curious if this is good or bad or just a matter of personal preference.
The default scope is package-private. All classes in the same package can access the method/field/class. Package-private is stricter than protected and public scopes, but more permissive than private scope.
The default access for a class member in C# is private. Member variables i.e. class members are the attributes of an object (from design perspective) and they are kept private to implement encapsulation. These variables can only be accessed using the public member functions.
In other words the default scope of a C# class is internal.
Class members, including nested classes, can be public, protected internal, protected, internal, private, or private protected. Members are private by default.
Cleaner code is more explicit as to the designer's intentions. Using private
demonstrates a deliberate choice, not open to debate. Falling to the default opens up the questions: was this on purpose, or he simply forgot to include a modifier?
Remove the private and Ask your fellow developers whether they are confused or not
Personally i feel, including private make your code more readable. I would give more importance to "Readability" than "being cleaner"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With