WIen I create a new class file, Visual Studio does not make it public by default. Can I change this?
By default a class without an access specifier is internal and a member defaults to private. This it keeps the visibility as restricted as possible and thereby increases encapsulation.
Making a new class public without even thinking about breaks the entire idea of encapsulation.
The class template that VS uses to create a new class can be found in this zip file (in case of CSharp):
C:\Program Files\Microsoft Visual Studio 8\Common7\IDE\ItemTemplates\CSharp\1033\Class.zip or C:\Program Files\Microsoft Visual Studio 9.0\Common7\IDE\ItemTemplates\CSharp\Code\1033 when using VS Orcas
Open the zip file, add the public keyword, save it and you're done. Every time you add a class it will be public. Hope this helps.
Source
There are other issues with the default code templates - for example, they are not compliant with StyleCop out of the box, since the "using" lines are outside the namespace declaration.
You could use ReSharper to create your class files from templates, allowing you to put any code you want into the template. That's what I do :)
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