C# Programming Language
C# | |
---|---|
Paradigm | Multi-paradigm (object-oriented, imperative, functional, component-oriented) |
Designed by | Anders Hejlsberg |
Developer | Microsoft |
First appeared | 2000 |
Stable release | C# 12 (2023) |
Typing discipline | Static, strong, safe, nominative, partially inferred |
Platform | .NET |
License | Open-source (MIT) |
C# (pronounced "C-sharp") is a modern, object-oriented programming language developed by Microsoft. It was first released in 2000 as part of the .NET Framework. The language was designed by Anders Hejlsberg, who also created Turbo Pascal and Delphi.
History
- 1999–2000: Microsoft begins developing C# for the .NET project.
- 2000: First announced at the Professional Developers Conference (PDC).
- 2002: Released with .NET Framework 1.0.
- 2005: C# 2.0 adds generics, nullable types, and anonymous methods.
- 2007–2010: C# 3.0 and 4.0 add LINQ, lambdas, and dynamic binding.
- 2015: C# 6.0 introduces string interpolation and simplified syntax.
- 2017: C# 7.x adds tuples, pattern matching, local functions.
- 2020+: With .NET 5–8, C# becomes cross-platform with records and top-level statements.
Design Goals
- Simplicity – Easy to learn for developers familiar with C, C++, Java.
- Modernity – Garbage collection, type safety, safe code.
- Object-Oriented – Everything revolves around objects and types.
- Component-Oriented – Supports modular, reusable software design.
- Interoperability – Works with the .NET ecosystem.
Example Code
Hello World
using System;
class Program
{
static void Main()
{
Console.WriteLine("Hello, World!");
}
}
Basic Class Example
using System;
public class Person
{
public string Name { get; set; }
public int Age { get; set; }
public void Greet()
{
Console.WriteLine($"Hello, my name is {Name} and I am {Age} years old.");
}
}
class Program
{
static void Main()
{
Person p = new Person { Name = "Alice", Age = 30 };
p.Greet();
}
}
LINQ Example
using System;
using System.Linq;
class Program
{
static void Main()
{
int[] numbers = { 1, 2, 3, 4, 5 };
var evenNumbers = numbers.Where(n => n % 2 == 0);
Console.WriteLine("Even numbers:");
foreach (var num in evenNumbers)
{
Console.WriteLine(num);
}
}
}
Modern Usage
- Windows apps – WPF, WinForms, UWP
- Web development – ASP.NET Core
- Game development – Unity Engine
- Cloud services – Azure APIs
- Cross-platform apps – .NET MAUI, Xamarin