KB Controls is reader-supported. When you buy through links on our site, we may earn an affiliate commission. Read more in our disclaimer
In this part of the series, we learn how to create a new C# .NET Console Application using the .NET CLI.
Welcome to another edition of C# From Scratch, a course dedicated to teaching you everything you need to know to be productive with C#. If you’re new here, head over to the index to see all parts of the series.
In the last part of the series, we learned how to interact with .NET using the .NET CLI. In this part of the series, we’ll learn how to create a new C# .NET project and look at the basic structure of a C# .NET project.
The dotnet new command is used to create a new C# .NET project. If you run this command in the Command Prompt, the CLI comes back with some additional information and a list of options that can be used with the command.
Basically, the CLI is asking us what template we want to use to create our new project. .NET uses a project template to create the basic structure for a new project.
In this course, we will focus on creating Console Applications. These are applications that do not have a user interface and are run from the Command Prompt window.
You can see from the output of the dotnet new command that the option to create a Console Application is console.
Before we create our application, we will make a directory that contains our application. To create a new directory, you can use the mkdir command and provide a name for the new directory. For our first application, you can call the directory Hello.
To move into this directory, use the cd command along with the name of the new directory. You should see that you are now in the Hello directory.
In this new directory, run the command dotnet new console to create a new Console Application.
You can verify that the project has been created by using the dir command to list the contents of the directory.
We can see that a number of files have been created in the Hello directory. These files are your Console Application project.
The first file listed is Hello.csproj. The csproj extension indicates that this is a C# Project file. This file contains information about your application that is used by the C# compiler to build your application into an executable file.
Next, we have a folder called obj. This folder contains some temporary files that the C# compiler uses to build your application into an executable file.
Finally, we have a file called Program.cs. The .cs extension indicates that this is a C# source code file. This file contains the source code for your application.
In this part of the series, we learned how to create a new .NET C# Console Application and looked at the basic structure of the project.
In the next part of the series, we will learn how to run our application and look at what .NET is doing in the background when we build and run a .NET application.
In this post, we learn how to debug a C# .NET Console application using the Console messages and Visual Studio Code's debugger. We also learn how to use conditional statements to avoid exceptional situations.
In this part of the series, we learn how to add interactivity to our application. Along the way, we will learn about methods, arrays, and string manipulation in C#.