Getting Started

C# Introduction

Get started with C# — Microsoft's elegant, modern language for .NET development.

What is C#?

C# (pronounced "C sharp") is a modern, object-oriented programming language developed by Microsoft. It runs on the .NET platform and is used for web, desktop, mobile, game development (Unity), and cloud applications.

Why C#?

  • Modern language: Constant innovation (LINQ, async/await, records, nullable types)
  • Strongly typed: Catch errors at compile time
  • Versatile: Web APIs (ASP.NET), Windows apps (WPF/MAUI), games (Unity), ML.NET
  • Great tooling: Visual Studio and VS Code provide excellent C# support
  • Cross-platform: .NET runs on Windows, macOS, and Linux

.NET vs .NET Framework

  • .NET (formerly .NET Core): Modern, cross-platform, open-source — use this!
  • .NET Framework: Windows-only, legacy

Getting Started

bash
dotnet new console -n MyApp
cd MyApp
dotnet run

Example

csharp
// Hello World in C#
using System;

namespace MyApp
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine("Hello, C#!");

            // Variables
            int age = 25;
            double price = 19.99;
            string name = "Alice";
            bool isActive = true;
            var inferred = 42;  // type inference

            // String interpolation
            Console.WriteLine($"Hello, {name}! You are {age} years old.");
            Console.WriteLine($"Price: {price:C}");  // currency format

            // Modern C# top-level statements (no class/Main needed)
        }
    }
}

// Modern C# (C# 9+) top-level statements:
// Console.WriteLine("Hello, World!");
Try it yourself — CSHARP