Skip to main content

Introduction to C#

What is C#?​

C# (pronounced "C-sharp") is a modern, type-safe, object-oriented programming language developed by Microsoft. It was designed by Anders Hejlsberg and his team as part of the .NET initiative and was approved as a standard by ECMA and ISO.

Key characteristics of C#:

  • Type-safe: The C# compiler ensures that operations are performed only on variables of appropriate types.
  • Object-oriented: C# supports encapsulation, inheritance, and polymorphism.
  • Component-oriented: C# provides features like properties, events, and attributes that make it ideal for building software components.
  • Modern: C# continues to evolve with regular updates that introduce new features and improvements.
  • Versatile: C# can be used to build a wide range of applications, from desktop to web to mobile to cloud services.

Evolution of C# (Version History)​

C# has evolved significantly since its initial release, with each version introducing new features and improvements:

VersionYear.NET VersionKey Features
C# 1.02002.NET 1.0First release with basic OOP features
C# 2.02005.NET 2.0Generics, nullable types, iterators, anonymous methods
C# 3.02007.NET 3.5LINQ, lambda expressions, extension methods, anonymous types
C# 4.02010.NET 4.0Dynamic binding, named/optional parameters, covariance/contravariance
C# 5.02012.NET 4.5Async/await pattern
C# 6.02015.NET 4.6String interpolation, null-conditional operators, expression-bodied members
C# 7.02017.NET 4.7Tuples, pattern matching, local functions, ref returns
C# 7.1-7.32017-2018.NET 4.7-4.7.2Async Main, default literal, tuple naming, ref locals/returns
C# 8.02019.NET Core 3.0Nullable reference types, async streams, indices/ranges, switch expressions
C# 9.02020.NET 5Records, init-only properties, top-level statements, pattern matching enhancements
C# 10.02021.NET 6Global using directives, file-scoped namespaces, record structs, interpolated string handlers
C# 11.02022.NET 7Raw string literals, list patterns, required members, auto-default structs
C# 12.02023.NET 8Primary constructors, collection expressions, inline arrays, ref readonly parameters
C# 13.02024.NET 9Params collections, ref struct interfaces, partial properties, field keyword (preview)
C# 14.02025.NET 10Extension members, null-conditional assignment, field keyword, user-defined compound assignment
C# 15.0Preview.NET 11 (preview)Not yet released (expected ~Nov 2026) — preview features: collection expression arguments, union types, closed hierarchies

C# and the .NET Platform​

C# is closely tied to the .NET platform, which provides the runtime environment and libraries necessary for C# applications to run.

Components of the .NET Platform:​

  1. Common Language Runtime (CLR): The execution environment that manages memory, handles exceptions, and provides other services for running C# code.

  2. Base Class Library (BCL): A comprehensive collection of reusable types for common tasks such as string manipulation, data collection, database connectivity, and file I/O.

  3. Intermediate Language (IL): C# code is compiled into IL, which is then just-in-time (JIT) compiled to native code at runtime.

  4. Language Interoperability: The .NET platform supports multiple languages (C#, F#, Visual Basic), allowing them to work together seamlessly.

.NET Implementations:​

  • .NET (formerly .NET Core): Cross-platform, open-source implementation for building apps that run on Windows, Linux, and macOS.
  • .NET Framework: The original Windows-only implementation (now in maintenance mode).
  • Mono: An open-source implementation of .NET for platforms where the official .NET runtime isn't available.
  • Xamarin: An implementation for building mobile apps for iOS and Android.
  • .NET MAUI: Multi-platform App UI for building cross-platform desktop and mobile apps.

Key .NET Features:​

  • Cross-platform: Modern .NET runs on Windows, macOS, and Linux.
  • Open Source: The .NET platform is open source and community-driven.
  • Performance: .NET provides high-performance capabilities for demanding applications.
  • Microservices: .NET is well-suited for building microservices architectures.
  • Cloud-Ready: .NET integrates well with cloud platforms like Azure.

Getting Started with C#​

To start developing with C#, you'll need:

  1. Development Environment:

    • Visual Studio (Windows/Mac)
    • Visual Studio Code with C# extension (cross-platform)
    • JetBrains Rider (cross-platform)
  2. .NET SDK: Download from dotnet.microsoft.com

  3. Basic Commands:

    # Create a new console application
    dotnet new console -n MyFirstApp

    # Build the application
    dotnet build

    # Run the application
    dotnet run
  4. Hello World Example:

    // Using top-level statements (C# 9.0+)
    Console.WriteLine("Hello, World!");

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

Resources for Learning C#​