Get Started with C#: A Beginner’s Guide to Installation and First ProgramDiscover the versatility of C# and learn how to install it on your computer, whether you’re on Windows, macOS, or Linux. Follow our step-by-step guide to set up C# and run your first program, with options to use our free online compiler or install it locally.

Unlock the Power of C#: A Beginner’s Guide to Getting Started

Running C# Online: A Quick Start

If you want to dive into C# immediately, you can use an online compiler. This online editor allows you to run C# code directly in your browser, without any installation required.

Installing C# on Your Computer

To install C# on your computer, follow these steps:

Windows Installation

  1. Install VS Code: Download the Windows installer from the official VS Code website and follow the installation process.
  2. Check.NET SDK Version: Open the Command Prompt and run the following command to check if the.NET SDK is already installed:
    dotnet --version
  3. Download the.NET SDK Installer: Visit the.NET download page and download the recommended installer for your operating system.
  4. Run the Installer: Double-click the downloaded file to open the installer and follow the installation process.
  5. Verify the Installation: Open a new Command Prompt window and run the following command to check the.NET SDK version:
    dotnet --version

macOS Installation

  1. Install VS Code: Download the zipped file from the official VS Code website and install it by dragging the application into the Applications folder.
  2. Check.NET SDK Version: Open the Terminal app and run the following command to check if the.NET SDK is already installed:
    dotnet --version
  3. Download the.NET SDK Installer: Visit the official.NET website and download the latest version of the.NET SDK for macOS.
  4. Run the Installer: Go to your downloads folder and run the installer.
  5. Follow the Instructions: Agree to the software license agreement, choose the installation location, and enter your administrator password.
  6. Verify the Installation: Open the Terminal app and run the following command to check the.NET SDK version:
    dotnet --version

Linux (Ubuntu) Installation

  1. Install VS Code: Open the Terminal and update your package lists, then install VS Code:
    sudo apt update
    sudo apt install code
  2. Install SDK and Run Time: Install the.NET SDK, which includes everything you need to build and run C# applications:
    sudo apt install dotnet-sdk-3.1
  3. Verify the Installation: Run the following command to check the.NET SDK version:
    dotnet --version

Running Your First C# Program

Now that you have C# installed on your computer, it’s time to run your first program. Here’s what you need to do:

  1. Install the C# Extension in VS Code: Open VS Code and install the C# extension by Microsoft.
  2. Create a.NET Console Project: Run the following command to create a new console project named HelloWorld:
    dotnet new console -o HelloWorld
  3. Write Your C# Program: Open the Program.cs file and write your first C# code:
    using System;
    
    class HelloWorld 
    {
        static void Main(string[] args) 
        {
            Console.WriteLine("Hello, World!");    
        }
    }
  4. Run Your Program: Head back to the terminal and run the following command to see the output:
    dotnet run

Congratulations! You’ve successfully set up C# on your computer and run your first program.

Leave a Reply