Hello,
Is there a way to make the default access modifier public for variable/method/class declarations?
I think by default, class declarations are private yes?
Hello,
Is there a way to make the default access modifier public for variable/method/class declarations?
I think by default, class declarations are private yes?
You can't change the defaults. They default to the most restrictive.
The default accessibility (for the type) for a top-level type is internal
.
The default accessibility (for the type) for a nested type is private
.
The default accessibility for members is private.
The only time it isn't the most restrictive is for the explicit part of an automatically implemented property, where you can make it more restrictive by adding a modifier:
public int Foo {get;private set;}
The general rule is that the default is the most private access level which you could specify. The only slight variation on this is when you make one part of a property (usually the setter) more private than the rest of the property.
Being able to change the default would be extraordinarily confusing to people maintaining your code. There are many who argue that you should never use the defaults anyway always explicitly specifying the visibility.
You cannot change the behavior as rightly indicated by other answers
But you can edit your class template file, so that each time you add a class from your solution explorer, public
keyword would be prefixed to your newly added class.
see here to edit visual studio templates