Code generation features in Visual Studio

There are numerous ways that Visual Studio can help you generate, fix, and refactor code.


  • You can use code snippets to insert a template such as a switch block or an enum declaration.

  • You can use Quick Actions to generate code such as classes and properties, or to introduce a local variable. You can also use Quick Actions to improve code, for example to remove unnecessary casts and unused variables, or to add null checks before accessing variables.

  • You can refactor code to rename a variable, re-order method parameters, or synchronize a type with its filename, to name a few.


Each language service in Visual Studio provides its own code generation capabilities, so some features are only available in C#, and some are available in both C# and Visual Basic.

See also