Getting Started with .NET: Creating a "Hello, World!" Console Application
Getting Started with .NET: Creating a "Hello, World!" Console Application
C#CONSOLE APPLICATIONBEGINNER
Nurullah
2/11/20251 min read
Introduction
If you're new to .NET development, a great way to start is by creating a simple console application that prints "Hello, World!" to the screen. In this tutorial, we'll walk through the steps of setting up a .NET development environment, writing your first C# program, and running it.
Prerequisites
Before we begin, ensure that you have the following installed on your computer:
.NET SDK: You can download it from Microsoft's official site
A Code Editor: We recommend Visual Studio Code or Visual Studio.
Step 1: Create a New .NET Console Application
Open a terminal or command prompt and run the following command to create a new .NET console application:
mkdir HelloWorldApp cd HelloWorldApp dotnet new console
This command does the following:
mkdir HelloWorldApp creates a new directory for your project.
cd HelloWorldApp navigates into the directory.
dotnet new console creates a new console application.
Step 2: Open the Project
If you're using Visual Studio Code, open the project by running:
code .
Alternatively, if you're using Visual Studio, open the .csproj file inside Visual Studio.
Step 3: Edit the Program.cs File
Navigate to the Program.cs file in your project. By default, it contains some basic code. Modify it to print "Hello, World!":
using System; class Program { static void Main() { Console.WriteLine("Hello, World!"); } }
Explanation of the Code:
using System; imports the System namespace, which includes functionality for input and output.
class Program defines a class named Program.
static void Main() is the entry point of the application.
Console.WriteLine("Hello, World!"); prints "Hello, World!" to the console.
Step 4: Build and Run the Application
To run your application, execute the following command in the terminal:
dotnet run
You should see the following output:
Hello, World!
Conclusion
Congratulations! You've successfully created and run your first .NET console application. This is just the beginning of your journey with .NET and C#. From here, you can explore more features like user input, loops, and working with files.
Happy coding :)