

The benefit of code snippets is you can replace the parameters. You can find the list of all default code snippets here: C# code snippets. VS already provides us with lots of built-in code snippets, such as prop, if, while, for, try, etc. For example, if you type prop then press Tab in Visual Studio, VS will automatically generate a property in your class, then you can easily replace the property name. Let’s get started! Code snippetsĬode snippets are small blocks of reusable code that can be inserted in our code files by using a combination of hotkeys. Maybe you have more ideas but this article will mainly cover these four ways. NET world, we have such ways to help us generate code: Good developers are lazy developers because they don’t want to repeat the code over and over again.


Then you can choose the proper way for various scenarios. In this article, I will walk you through four ways that can generate source code to simplify our daily jobs. It is a new feature that allows us to generate source code when the code compiles. Microsoft introduced Source Generators in the latest C# version. 4 ways to generate code in C# - Including Source Generators in.
