Why are my classes Private by default in Visual Studio .net?
There was an interesting question stackoverflow today.
Why are my classes Private by default in Visual Studio .net?
Here is why
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.
Check out the question here.
.jpg)
Recent Comments