Codementor Events

Creating public class by default Visual Studio

Published Dec 27, 2017

Recently, I came across a silly mistake – where, I was not able to see my newly created class in intellisense in visual studio.

After starting from the scratch, it came to notice that by default visual studio creates class without access specifiers and that is the reason, it became private and it didn't show up in Intellisense.

You can fix it. Here is how. When you try creating new class, it uses the template located under path:

%systemdrive%\Program Files (x86)\Microsoft Visual Studio 14.0\Common7\IDE\ItemTemplates\CSharp\Code\1033\Class

You should see the file named class.cs which has content as below.

using System;
using System.Collections.Generic;
$if$ ($targetframeworkversion$ >= 3.5)using System.Linq;
$endif$using System.Text;
$if$ ($targetframeworkversion$ >= 4.5)using System.Threading.Tasks;
$endif$
namespace $rootnamespace$
{
class $safeitemrootname$
{
}
}

Here, change the class definition by adding Public access specifier and save/override the file.

public class $safeitemrootname$

You should be good to go.

Please leave your comments for any question concerns.

Please note that my post is open for suggestion(s) or correction(s).

Discover and read more posts from Tapan
get started
post commentsBe the first to share your opinion
Austin Bryan
3 years ago

Actually the default accessor for classes is internal, so it should’ve been accessible by all your classes in the project, so long as you were using the namespace if it had one.

Show more replies