C# Introduction
What is C#?
C# (pronounced "C Sharp") is a modern, general-purpose, object-oriented programming language developed by Microsoft. It is one of the main programming languages of the .NET platform, combining the powerful features of C++ with the ease of use of Visual Basic.
C# Development History
Historical Background
C# was developed by a team led by Microsoft's Anders Hejlsberg and first released in 2000. Anders Hejlsberg was also the main designer of Turbo Pascal and Delphi.
Version Evolution
| Version | Release Year | .NET Version | Main Features |
|---|---|---|---|
| C# 1.0 | 2002 | .NET 1.0 | Basic object-oriented features |
| C# 2.0 | 2005 | .NET 2.0 | Generics, anonymous methods, nullable types |
| C# 3.0 | 2007 | .NET 3.5 | LINQ, Lambda expressions, auto properties |
| C# 4.0 | 2010 | .NET 4.0 | Dynamic types, optional parameters |
| C# 5.0 | 2012 | .NET 4.5 | async/await asynchronous programming |
| C# 6.0 | 2015 | .NET 4.6 | String interpolation, null-conditional operators |
| C# 7.0 | 2017 | .NET 4.7 | Tuples, pattern matching |
| C# 8.0 | 2019 | .NET Core 3.0 | Nullable reference types, async streams |
| C# 9.0 | 2020 | .NET 5.0 | Record types, top-level programs |
| C# 10.0 | 2021 | .NET 6.0 | Global using, file-scoped namespaces |
| C# 11.0 | 2022 | .NET 7.0 | Raw string literals, generic attributes |
| C# 12.0 | 2023 | .NET 8.0 | Primary constructors, collection expressions |
C# Features
1. Object-Oriented
C# is a pure object-oriented programming language that supports:
- Encapsulation: Control member access through access modifiers
- Inheritance: Support for single inheritance and multiple interface implementation
- Polymorphism: Implemented through virtual methods and interfaces
// Object-oriented example
public class Animal
{
public virtual void MakeSound()
{
Console.WriteLine("Animal makes a sound");
}
}
public class Dog : Animal
{
public override void MakeSound()
{
Console.WriteLine("Dog barks");
}
}2. Type Safety
C# is a strongly typed language with type safety:
// Type safety example
int number = 42; // Explicit type
var text = "Hello"; // Type inference
string name = null; // Nullable reference type
int? age = null; // Nullable value type3. Modern Language Features
C# includes many modern programming features:
// Modern features example
var numbers = new[] { 1, 2, 3, 4, 5 };
var evenNumbers = numbers.Where(n => n % 2 == 0); // LINQ
await ProcessDataAsync(); // Async/await
var person = new { Name = "John", Age = 30 }; // Anonymous typeC# Applications
1. Desktop Applications
- Windows Forms: Traditional desktop applications
- WPF: Modern Windows applications with rich UI
- MAUI: Cross-platform desktop and mobile applications
2. Web Applications
- ASP.NET Core: Modern web applications and APIs
- Blazor: Web applications using C# instead of JavaScript
- MVC: Model-View-Controller web applications
3. Mobile Applications
- Xamarin: Cross-platform mobile applications
- MAUI: Evolution of Xamarin for modern mobile development
4. Game Development
- Unity: Popular game engine using C#
- Godot: Open-source game engine with C# support
5. Other Applications
- Cloud Services: Azure cloud applications
- Microservices: .NET microservice architecture
- Machine Learning: ML.NET for machine learning applications
C# and .NET Ecosystem
.NET Framework vs .NET Core vs .NET
- .NET Framework: Original Windows-only framework
- .NET Core: Cross-platform, open-source rewrite
- .NET: Unified platform combining the best of both
Development Tools
- Visual Studio: Main IDE for C# development
- VS Code: Lightweight editor with C# extension
- Rider: JetBrains C# IDE
- CLI: Command-line tools for .NET development
Why Choose C#?
Advantages
- Modern Language: Continuously updated with new features
- Strong Typing: Type safety reduces runtime errors
- Rich Ecosystem: Extensive libraries and frameworks
- Cross-Platform: Runs on Windows, macOS, and Linux
- Enterprise Ready: Widely used in enterprise applications
- Great Tooling: Excellent development tools and IDEs
- Performance: High performance with JIT compilation
When to Use C#
- Enterprise Applications: Large-scale business applications
- Web Development: Backend services and APIs
- Game Development: Unity game development
- Desktop Applications: Windows desktop software
- Cloud Services: Azure cloud applications
Getting Started
To start learning C#:
- Install .NET SDK: Download from dotnet.microsoft.com
- Choose an IDE: Visual Studio, VS Code, or Rider
- Create First Project: Simple console application
- Learn Basic Syntax: Variables, control structures, methods
- Practice Regularly: Write code and solve problems
Summary
C# is a powerful, modern programming language suitable for various types of applications. Its strong typing, object-oriented features, and rich ecosystem make it an excellent choice for both beginners and experienced developers.
In the next chapters, we will learn C# programming step by step, from basic syntax to advanced features.