Skip to main content
    Courses/C#/Introduction to C#

    Lesson 1 • Beginner Track

    Introduction to C#

    By the end of this lesson you'll understand what C# and .NET are, you'll have written and run your own C# program, and you'll be printing clean, formatted output with Console.WriteLine and string interpolation — the very first skills every C# developer needs.

    What You'll Learn

    • Understand what C# is and why it's one of the most in-demand programming languages
    • Learn how C# fits into the .NET ecosystem (desktop, web, games, mobile)
    • Write and run your first C# program with Console.WriteLine()
    • Understand the anatomy of a C# program: using, class, Main, and statements
    • Use string interpolation to combine text and variables in output
    • Know the difference between Console.Write() and Console.WriteLine()

    💡 Real-World Analogy

    Think of C# as a universal remote control. Just like one remote can control your TV, sound system, and streaming box, C# can build desktop apps, websites, mobile apps, and games — all with the same language. The .NET framework is the signal receiver that makes everything work together. You learn one "remote" and control an entire ecosystem.

    What is C# and .NET?

    C# (pronounced "C Sharp") is a modern, object-oriented programming language created by Microsoft in 2000. It was designed by Anders Hejlsberg (who also created TypeScript and Delphi) to be powerful yet approachable — combining the performance of C++ with the productivity of languages like Java and Python.

    C# runs on the .NET platform, which provides a massive standard library, a garbage collector for automatic memory management, and cross-platform support. With .NET 8+, your C# code runs on Windows, macOS, and Linux. Here's what you can build:

    • 🎮 Games — Unity (the world's most popular game engine) uses C# exclusively
    • 🌐 Web APIs & Websites — ASP.NET Core powers enterprise backends at Microsoft, Stack Overflow, and more
    • 🖥️ Desktop Apps — Windows Forms, WPF, and .NET MAUI for cross-platform UIs
    • 📱 Mobile Apps — .NET MAUI and Xamarin for iOS/Android from a single codebase
    • ☁️ Cloud & Microservices — Azure Functions, gRPC services, and containerised APIs

    C# is consistently ranked in the top 5 most in-demand programming languages, with average salaries ranging from £35,000–£75,000 (UK) and $60,000–$130,000 (US) depending on specialisation.

    📊 C# Program Anatomy

    PartCodeWhat It Does
    Using directiveusing System;Imports the System namespace so you can use Console
    Class declarationclass Program {}Every C# program lives inside a class
    Main methodstatic void Main()The entry point — where your program starts running
    StatementConsole.WriteLine("...");An instruction that does something — ends with ;
    String interpolation$"Hello {name}"Embed variables inside strings with $ prefix

    🖥️ Setting Up C#

    You can practise C# right here in the browser, but to run C# on your own machine:

    Option 1: Visual Studio (Recommended for Windows)

    1. Download Visual Studio Community (free) from visualstudio.microsoft.com
    2. Select the ".NET desktop development" workload during installation
    3. Create a new "Console App" project and start coding

    Option 2: VS Code + .NET SDK (All platforms)

    1. Install the .NET SDK from dotnet.microsoft.com
    2. Install VS Code with the C# extension
    3. Run dotnet new console -n MyApp in terminal, then dotnet run

    Option 3: Online (No install)

    Use dotnetfiddle.net or the code editors in this course to practise instantly.

    1. Your First C# Program

    Every C# journey starts with "Hello, World!". Console.WriteLine() prints text to the console and then moves to a new line. The text you want to print goes inside "double quotes", and the whole statement ends with a semicolon ;. Read this worked example first and run it, then you'll write your own.

    Worked example: Hello World

    Read every comment, run it, and check the output matches.

    Try it Yourself »
    C#
    using System;
    
    class Program
    {
        static void Main()
        {
            // Console.WriteLine prints a line of text, then moves to a NEW line.
            Console.WriteLine("Hello, C# World!");      // prints: Hello, C# World!
            Console.WriteLine("Welcome to C# programming!"); // prints on its own line
            Console.WriteLine("Let's build something amazing!");
    
            // ✅ Expected output (three separate lines):
            //    Hello, C# World!
            //    Welcome to C# programming!
            //  
    ...

    Your turn. The program below is almost complete — fill in the two blanks marked ___ with your own text (remember the "double quotes"), then run it.

    🎯 Your turn: print two messages

    Fill in the ___ blanks, then check your output against the expected lines.

    Try it Yourself »
    C#
    using System;
    
    class Program
    {
        static void Main()
        {
            // 🎯 YOUR TURN — replace each ___ then press "Try it Yourself".
    
            // 1) Print a greeting of your choice
            Console.WriteLine(___);   // 👉 put your text in "double quotes"
    
            // 2) Print your name on its own line
            Console.WriteLine(___);   // 👉 e.g. "My name is Sam"
    
            // ✅ Expected output (example):
            //    Hello there!
            //    My name is Sam
        }
    }

    2. Console Output & String Interpolation

    Console.Write() prints without a new line, so the next output continues on the same line, while Console.WriteLine() finishes the line for you. String interpolation — the $"..." syntax — lets you drop variables straight into text inside {curly braces}, which reads far better than gluing strings together with +. Escape characters like \n (new line) and \t (tab) let you shape the layout.

    Worked example: Write, WriteLine & interpolation

    See the difference between Write and WriteLine, plus interpolation and escapes.

    Try it Yourself »
    C#
    using System;
    
    class Program
    {
        static void Main()
        {
            // WriteLine adds a new line at the end; Write does NOT.
            Console.WriteLine("=== Welcome to C# ===");
            Console.Write("This stays on ");          // no new line after this
            Console.WriteLine("the same line.");      // joins: This stays on the same line.
    
            // $"..." is string interpolation: {variable} is swapped for its value.
            string language = "C#";
            int year = 2026;
            Console.Writ
    ...

    Now you try. Fill in the two blanks: one puts a variable inside interpolation braces, the other prints a number on the same line as some text.

    🎯 Your turn: interpolation & same-line output

    Fill in the ___ blanks, then check your output against the expected lines.

    Try it Yourself »
    C#
    using System;
    
    class Program
    {
        static void Main()
        {
            // 🎯 YOUR TURN — fill in the blanks marked with ___
    
            string course = "C#";
    
            // 1) Use interpolation to print "I'm learning C# today!"
            Console.WriteLine($"I'm learning {___} today!"); // 👉 put the variable name in the braces
    
            // 2) Use Write (no new line) then WriteLine so both appear on ONE line
            Console.Write("Score: ");
            Console.WriteLine(___);   // 👉 print the number 100 (no qu
    ...

    3. A Taste of Variables

    Variables store data. C# is strongly typed, which means every variable has a specific type (string, int, double, bool) that fixes what it can hold. You'll cover types in depth in the very next lesson, but here's a preview so the next lesson feels familiar:

    Worked example: a first look at variables

    See how different data types work in C#.

    Try it Yourself »
    C#
    using System;
    
    class Program
    {
        static void Main()
        {
            // A variable is a named box that stores ONE type of value.
            string name = "Alice";    // text  -> always in "double quotes"
            int age = 25;             // whole number (no decimal point)
            double height = 1.68;     // decimal number
            bool isStudent = true;    // true or false (lowercase in C#)
    
            // Drop each variable into the text with {curly braces}.
            Console.WriteLine($"Name: {name}"); 
    ...

    Pro Tips

    • 💡 C# is case-sensitive: Console works, console doesn't. Watch your capitalisation.
    • 💡 Every statement ends with a semicolon (;) — forgetting it is the most common beginner error.
    • 💡 Use string interpolation ($"...") instead of concatenation ("Hello " + name). It's cleaner and easier to read.
    • 💡 C# 9+ supports top-level statements: you can skip the class and Main method for simple programs. But learn the full structure first — you'll need it for real projects.

    Common Errors (and the fix)

    • "CS1002: ; expected" — you forgot the semicolon at the end of a statement. Every statement must end with ;, e.g. Console.WriteLine("Hi");.
    • "CS0103: The name 'Console' does not exist in the current context" — you're missing using System; at the top, so the compiler doesn't know what Console is. Add that line.
    • "CS0234: The type or namespace name '…' does not exist in the namespace 'System'" — a using points at something that isn't there (a typo or a missing package). Check the namespace spelling.
    • "CS0117: 'Console' does not contain a definition for 'Writeline'" — wrong capitalisation. It must be Console.WriteLine with a capital L; C# is case-sensitive.
    • "CS1525 / CS1056: Unexpected/invalid token" — usually a mismatched brace. Every { needs a matching }; use an editor that highlights matching braces.
    • "CS1012: Too many characters in character literal" — you used 'single quotes' around text. Strings use "double quotes"; single quotes are only for one char like 'A'.

    📋 Quick Reference

    TaskCodeResult
    Print a lineConsole.WriteLine("Hi");Hi (then new line)
    Print, no new lineConsole.Write("Hi");Hi (cursor stays)
    Interpolation$"Hi {name}"Hi Sam
    New line inside text"Line1\nLine2"two lines
    Tab inside text"A\tB"A    B
    Import for Consoleusing System;enables Console

    Frequently Asked Questions

    Q: What's the difference between Console.Write and Console.WriteLine?

    WriteLine prints your text and then moves to a new line. Write prints your text but leaves the cursor right after it, so the next output continues on the same line.

    Q: Why do I need using System; at the top?

    Console lives in the System namespace. The using System; line tells the compiler where to find it. Leave it out and you get CS0103: The name 'Console' does not exist.

    Q: Do I really have to write the class and Main every time?

    Modern C# (9+) supports "top-level statements" that let you skip them for small programs. But the full structure is what real projects use, so it's worth learning first — that's why this course shows it.

    Q: Why did my code break when I typed console.writeline?

    C# is case-sensitive. It must be Console.WriteLine with the capital C, W, and L. Capitalisation is part of the name, not a style choice.

    Mini-Challenge: "About Me" Banner

    No blanks this time — just a brief and a blank canvas (with a comment outline to keep you on track). Write it yourself, run it, and check your output against the example in the comments. This is exactly the kind of small program you'll build constantly.

    🎯 Mini-Challenge: build an 'About Me' banner

    Write the WriteLine calls yourself and print a bordered banner.

    Try it Yourself »
    C#
    using System;
    
    class Program
    {
        static void Main()
        {
            // 🎯 MINI-CHALLENGE: "About Me" banner
            // 1. Print a top border line, e.g.  "====================="
            // 2. Print three facts about you on three lines using Console.WriteLine,
            //    and use string interpolation ($"...") for at least one of them.
            // 3. Print a matching bottom border line.
            //
            // ✅ Example output:
            //    =====================
            //    Name: Sam
            //  
    ...

    🎉 Lesson Complete

    • ✅ C# is a modern, versatile language for games, web, desktop, and mobile
    • ✅ .NET is the platform that runs C# code on Windows, macOS, and Linux
    • ✅ Every program needs using System;, a class, and a Main method
    • Console.WriteLine() prints with a new line; Console.Write() prints without
    • ✅ String interpolation: $"Hello {name}" embeds variables in strings
    • ✅ C# is strongly typed — every variable has a declared type
    • ✅ Statements end with ; and code blocks use {} braces
    • Next lesson: Variables & Data Types — the building blocks of every program

    Sign up for free to track which lessons you've completed and get learning reminders.

    Cookie & Privacy Settings

    We use cookies to improve your experience, analyze traffic, and show personalized ads. You can manage your preferences below.

    By clicking "Accept All", you consent to our use of cookies for analytics and personalized advertising. You can customize your preferences or reject non-essential cookies.

    Privacy PolicyTerms of Service