In this 10-minute introduction to the code editor in Visual Studio, we'll add code to a file to look at some of the ways that Visual Studio makes writing, navigating, and understanding C# code easier.
If you haven't already installed Visual Studio, go to the Visual Studio downloads page to install it for free.
This article assumes you're already familiar with C#. If you aren't, we suggest you look at a tutorial such as Get started with C# and ASP.NET Core in Visual Studio first.
Tip
To follow along with this article, make sure you have the C# settings selected for Visual Studio. For information about selecting settings for the integrated development environment (IDE), see Select environment settings.
Create a new code file
Start by creating a new file and adding some code to it.
Use code snippets
Visual Studio provides useful code snippets that you can use to quickly and easily generate commonly used code blocks. Code snippets are available for different programming languages including C#, Visual Basic, and C++.
Let's add the C# void Main snippet to our file.
The list includes snippets for creating a class, a constructor, a for loop, an if or switch statement, and more.
Comment out code
Collapse code blocks
We don't want to see the empty constructor that was generated for Class1, so to unclutter our view of the code, let's collapse it. Choose the small gray box with the minus sign inside it in the margin of the first line of the constructor. Or, if you prefer to use the keyboard, place the cursor anywhere in the constructor code and press Ctrl+M, Ctrl+M.