Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

VS.NET defaults to private class

Why does Visual Studio declare new classes as private in C#? I almost always switch them over to public, am I the crazy one?

like image 414
Jake Pearson Avatar asked Sep 02 '08 16:09

Jake Pearson


1 Answers

I am not sure WHY it does that, but here's what you do in order to get Visual Studio to create the class as Public by default:

Go over to “Program Files\Microsoft Visual Studio 9.0\Common7\IDE\ItemTemplates\CSharp\Code\1033″, you will find a file called Class.zip, inside the .zip file open the file called Class.cs, the content of the file looks like this:

using System;
using System.Collections.Generic;
$if$ ($targetframeworkversion$ == 3.5)using System.Linq;
$endif$using System.Text;   

namespace $rootnamespace$
{
    class $safeitemrootname$
    {
    }
}

All you need to do is add “Public” before the class name. The outcome should look like this:

using System;
using System.Collections.Generic;
$if$ ($targetframeworkversion$ == 3.5)using System.Linq;
$endif$using System.Text;   

namespace $rootnamespace$
{
    public class $safeitemrootname$
    {
    }
}

One last thing you need to do is flush all the Templates Visual Studio is using, and make him reload them. The command for that is ( it takes a while so hold on):

devenv /installvstemplates

And that’s it, no more private classes by default. Of course you can also add internal or whatever you want.

Source

like image 103
Espo Avatar answered Oct 26 '22 23:10

Espo