Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Default access modifier for new C#-classes in Visual Studio 2022

When I generate a new class in Visual Studio (C#), I would like to have the default access modifier changed from "internal" to "public". E.g.:

public class Animal
{
}

instead of:

internal class Animal
{
}

Is there a setting in Visual Studio (2022) where the default access modifier for new classes can be set?

like image 620
StOp Avatar asked Sep 02 '25 06:09

StOp


2 Answers

I tried same for Visual Studio Community 2022 (V 17.1.0)

Open Class.cs at

%ProgramFiles%\Microsoft Visual Studio\2022\Community\Common7\IDE\ItemTemplates\CSharp\Code\1033\Class\Class.cs

The Class.cs file location depends on your installation directory.

Existing class code

class $safeitemrootname$
{
}

Add public keyword

public class $safeitemrootname$
{
}

and Save the file. It's working on my machine.

like image 184
Rohit Jadhav Avatar answered Sep 04 '25 20:09

Rohit Jadhav


You can change it at

%ProgramFiles%\Microsoft Visual Studio\2022\Enterprise\Common7\IDE\ItemTemplates\CSharp\Code\1033\Class

like image 37
Alireza Orumand Avatar answered Sep 04 '25 18:09

Alireza Orumand