Your First C# Application

Welcome to the world of C#! This guide will walk you through creating your very first C# application. We'll start with a simple "Hello, World!" program, which is a traditional first step in learning any new programming language.

Prerequisites

Before you begin, ensure you have the following installed:

Creating Your Project

We'll use the .NET CLI (Command Line Interface) to create our project. Open your terminal or command prompt and navigate to the directory where you want to create your project. Then, run the following command:

dotnet new console -o MyFirstApp

This command does the following:

Now, change your directory into the newly created project folder:

cd MyFirstApp

Exploring the Project Files

Inside the MyFirstApp folder, you'll find a few files. The most important one for now is Program.cs. This is where your application's code will reside.

Note: The structure of the generated project might vary slightly depending on your .NET SDK version, but the core concept remains the same.

Writing Your First Code

Open the Program.cs file in your code editor. You'll likely see something like this:

using System;

            namespace MyFirstApp
            {
                class Program
                {
                    static void Main(string[] args)
                    {
                        Console.WriteLine("Hello, World!");
                    }
                }
            }

Let's break down this code:

Running Your Application

To run your application, go back to your terminal or command prompt, make sure you are still in the MyFirstApp directory, and run the following command:

dotnet run

You should see the following output in your terminal:

Hello, World!
Tip: If you are using an IDE like Visual Studio or Visual Studio Code, you can usually run your application by pressing a "Run" button or using a keyboard shortcut (e.g., F5 in Visual Studio).

Next Steps

Congratulations! You've successfully created and run your first C# application. This is just the beginning. From here, you can explore variables, data types, control flow statements, and much more to build more complex and powerful applications.

Continue your journey by exploring the other sections of our C# documentation:

Explore Variables and Data Types