C#

Modern, object-oriented language by Microsoft

C# Overview

C# (pronounced "See Sharp") is a modern, object-oriented, and type-safe programming language. C# enables developers to build many types of secure and robust applications that run in .NET.

Paradigm

Structured, imperative, object-oriented, event-driven, task-driven, functional, generic, reflective, concurrent

Designed by

Microsoft (Anders Hejlsberg)

First appeared

2000

Stable release

C# 11.0 (.NET 7.0, November 2022)

Key Features

Common Use Cases

Windows Applications

Used with WPF, Windows Forms, and UWP for desktop apps.

Web Development

ASP.NET Core for building web applications and APIs.

Game Development

Primary language for Unity game engine.

Enterprise Software

Used for business applications and services.

Example Code

// Modern C# example demonstrating OOP and features
using System;

namespace CSharpExample
{
    class Program
    {
        static void Main(string[] args)
        {
            // Pattern matching
            object greeting = "Hello, World!";
            if (greeting is string message)
            {
                Console.WriteLine(message.ToUpper());
            }

            // Create a person using record (immutable)
            var person = new Person("Alice", 30);
            Console.WriteLine(person);

            // LINQ example
            var numbers = new[] { 1, 2, 3, 4, 5 };
            var squares = numbers.Select(x => x * x);
            Console.WriteLine(string.Join(", ", squares));
        }
    }

    // Record type (immutable)
    public record Person(string Name, int Age);

    // Interface and class example
    public interface IShape
    {
        double Area { get; }
    }

    public class Circle : IShape
    {
        public double Radius { get; }

        public Circle(double radius) => Radius = radius;

        public double Area => Math.PI * Radius * Radius;
    }
}

Learning Resources