Skip to content

CSharp Basics HelloWorld

Joe Care edited this page Dec 22, 2025 · 1 revision

C# Basics: Hello World and Console Output

This lesson walks through a minimal "Hello, World!" program and a few variables.

Related wiki pages:

  • Overview: CSharpBible.md
  • Basics of Console.WriteLine: CSharp-Basics-ConsoleWriteLine-DateTime.md

Official docs:


1. Hello World

using System;

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

2. Adding variables

using System;

namespace HelloWorldProject
{
    class Program
    {
        static void Main(string[] args)
        {
            int score = 100;
            string name = "Alice";
            double pi = 3.14159;

            Console.WriteLine("Hello, World!");
            Console.WriteLine("Name: " + name);
            Console.WriteLine("Pi: " + pi);
        }
    }
}

3. Running with .NET SDK

From a terminal:

dotnet new console -n HelloWorldProject
cd HelloWorldProject
# replace Program.cs with one of the examples

dotnet run

4. Next steps

  • Combine this with input from Lesson20.12.2025.md.
  • Explore more examples in CSharp-Basics-ConsoleWriteLine-DateTime.md.

Clone this wiki locally