Setting Up and Running Your First .NET Console Application

by Gautham Pai

1. Setting Up Your Development Environment

Downloading .NET

To start programming with .NET, you'll first need to download the .NET SDK. You can find the latest version and download it from here.

Installing .NET 8.0 SDK on Ubuntu

For Ubuntu users, you can follow the instructions to install the .NET 8.0 SDK from this guide.

Installing VS Code Extensions

To enhance your development experience in Visual Studio Code (VS Code), install the following extensions:

  • ms-dotnettools.csharp
  • ms-dotnettools.csdevkit
  • ms-dotnettools.vscode-dotnet-runtime

2. Creating and Running a .NET Console Application

Opening the Terminal in VS Code

  1. Open the Terminal in VS Code.
  2. Ensure the dotnet command is accessible by running:
    dotnet --info
    

Creating a New Console App

To create a new console application, use the following command:

dotnet new console -o HelloWorld

Running the Application

Navigate into the project directory and run the application:

cd HelloWorld
dotnet run

3. Understanding C# Top-Level Statements

Introduction to Top-Level Statements

Top-level statements provide a simplified syntax for writing C# programs. Instead of defining a Main method within a Program class, you can write:

Console.WriteLine("My Hello World!");

This is a shorthand for:

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

Test Your Knowledge

No quiz available

Tags