In Visual Studio when you add a new class, it always created with no modifiers and that makes class internal.
class MyClass { }
I would prefer that my class by default is created as public one.
Why is it internal by default?
What would you prefer?
Classes are internal by default. Class members, including nested classes, can be public, protected internal, protected, internal, private, or private protected. Members are private by default.
internal is useful when you want to declare a member or type inside a DLL, not outside that. Normally, when you declare a member as public , you can access that from other DLLs. But, if you need to declare something to be public just inside your class library, you can declare it as internal .
To add a class in a Visual Studio C++ project, in Solution Explorer, right-click the project, choose Add, and then choose Class. This command opens the Add Class dialog box. When you add a class, you must specify a name that is different from classes that already exist in MFC or ATL.
Choose File > New > Project from the menu bar. Select the template that you want to update and continue through the steps to create the new project. Modify the project in Visual Studio. For example, change the output type or add a new file to the project.
Making class internal
by default makes perfect sense to me: keep your privates to yourself and only explicitly expose parts which really need to be exposed: everything else is just implementation details and should not be visible to the outside world.
In case you want to test your internal
classes, .NET 2.0 onwards introduces a new attribute called InternalsVisibleToAttribute, which
Specifies that types that are ordinarily visible only within the current assembly are visible to another assembly.
If this really annoys you, see %ProgramFiles%\Microsoft Visual Studio 8\Common7 IDE\ItemTemplates\CSharp\1033\Class.zip
. This is a template which you can change to suit your needs. ReSharper has similar capability, but it's directly accessible from within th UI.
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