Courses/C#/Introduction to C#

    Introduction to C#

    Lesson 1 โ€ข Beginner Track

    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 moves to a new line. Try modifying the messages below:

    Your First C# Program

    Print messages to the console with Console.WriteLine().

    Try it Yourself ยป
    C#
    using System;
    
    class Program
    {
        static void Main()
        {
            Console.WriteLine("Hello, C# World!");
            Console.WriteLine("Welcome to C# programming!");
            Console.WriteLine("Let's build something amazing!");
        }
    }

    2. Console Output & String Interpolation

    Console.Write() prints without a newline (the next output continues on the same line). String interpolation with $"" lets you embed variables directly inside strings โ€” much cleaner than concatenation.

    Console Output & Interpolation

    Explore Write vs WriteLine and string interpolation.

    Try it Yourself ยป
    C#
    using System;
    
    class Program
    {
        static void Main()
        {
            // Writing output
            Console.WriteLine("=== Welcome to C# ===");
            Console.Write("This stays on ");
            Console.WriteLine("the same line.");
    
            // String interpolation
            string language = "C#";
            int year = 2024;
            Console.WriteLine($"Learning {language} in {year}!");
    
            // Escape characters
            Console.WriteLine("Line 1\nLine 2");
            Console.WriteLine("Tab\there");
            C
    ...

    3. A Taste of Variables

    Variables store data. C# is strongly typed โ€” every variable has a specific type (string, int, double, bool). We'll cover types in depth in the next lesson, but here's a preview:

    Variables Preview

    See how different data types work in C#.

    Try it Yourself ยป
    C#
    using System;
    
    class Program
    {
        static void Main()
        {
            // Variables hold data
            string name = "Alice";
            int age = 25;
            double height = 1.68;
            bool isStudent = true;
    
            Console.WriteLine($"Name: {name}");
            Console.WriteLine($"Age: {age}");
            Console.WriteLine($"Height: {height}m");
            Console.WriteLine($"Student: {isStudent}");
        }
    }

    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 Mistakes

    • Missing semicolons โ€” Every statement must end with ;. The compiler will give you a "CS1002: ; expected" error.
    • Wrong capitalisation โ€” Console.Writeline won't work. It must be Console.WriteLine with a capital L.
    • Mismatched braces โ€” Every { needs a matching }. Use an editor that highlights matching braces.
    • Forgetting "using System;" โ€” Without this, the compiler doesn't know what Console is. You'll get a "CS0103: The name 'Console' does not exist" error.
    • Using single quotes for strings โ€” In C#, strings use double quotes "hello". Single quotes 'h' are for individual characters (char type).

    ๐ŸŽ‰ 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 newline; 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 Policy โ€ข Terms of Service