Introduction to C#
Introduction to C#
1. What is C#?
C# (pronounced C-Sharp) is a modern, object-oriented programming language developed by Microsoft.
It is designed for building a variety of applications that run on the .NET framework.
Key Points:
- Strongly-typed, statically-typed language.
- Designed for simplicity and safety.
- Supports Object-Oriented Programming (OOP).
- Can be used for Web, Desktop, Mobile, Cloud, and Game development.
2. History & Evolution of C#
- 1999: Developed by Anders Hejlsberg at Microsoft.
- 2000: C# 1.0 released with .NET Framework 1.0.
- 2005: C# 2.0 introduced Generics, Partial Classes.
- 2007: C# 3.0 added LINQ and Lambda expressions.
- 2010: C# 4.0 included dynamic types and named arguments.
- 2012-2015: C# 5.0 & 6.0 added Async/Await and improved syntax.
- 2017-2021: C# 7.0 to 9.0 added Tuples, Pattern Matching, Records.
- 2022+: C# 10, 11, 12 (latest) improved performance, minimal APIs, global using, and enhanced pattern matching.
3. Features of C#
- Simple & Modern: Clean syntax, easy to learn for beginners.
- Object-Oriented: Supports OOP concepts like Classes, Objects, Inheritance, Polymorphism, Encapsulation, and Abstraction.
- Type-Safe: Prevents type errors at compile time.
- Managed Code: Runs on .NET CLR (Common Language Runtime).
- Interoperable: Can work with other languages on the .NET platform.
- Versatile: Can build Web, Desktop, Mobile, Cloud, and Games.
- Rich Library: Access to .NET libraries for networking, file handling, database, GUI, etc.
4. .NET Framework vs .NET Core vs .NET 5/6/7/8
| Feature.NET Framework.NET Core.NET 5/6/7/8 | |||
| Platform Support | Windows only | Cross-platform (Win, Mac, Linux) | Cross-platform |
| Open Source | Partially | Open Source | Open Source |
| Performance | Moderate | High | High & optimized |
| App Types | Desktop, Web, Windows Services | Console, Web, Cloud | Console, Web, Cloud, Mobile |
| Future Support | Legacy | Supported, but replaced by .NET 5+ | Latest & active support |
Recommendation:
Use .NET 6 or .NET 8 for new projects because it is the latest LTS version and cross-platform.
5. Applications of C#
C# can be used to develop:
- Web Applications: ASP.NET Core, Blazor, REST APIs.
- Desktop Applications: Windows Forms, WPF.
- Mobile Applications: Xamarin, .NET MAUI (iOS & Android).
- Game Development: Unity engine.
- Cloud Applications: Azure services.
- IoT Applications: .NET IoT libraries.
6. Setting up Environment
To start programming in C#, you need an IDE:
Option 1: Visual Studio (Recommended for Windows)
- Download: Visual Studio
- Choose Community Edition (free) or Professional/Enterprise.
- During installation, select “.NET desktop development” workload.
- Install & launch Visual Studio.
Option 2: VS Code (Lightweight & Cross-platform)
- Download: Visual Studio Code
- Install .NET SDK (latest version) from here.
- Install C# extension in VS Code.
- Open terminal and verify installation:
7. Your First Program: Hello World
Step 1: Create a Console Project
Step 2: Open Program.cs
Step 3: Run the Program
Expected Output:
Explanation:
using System;→ Includes the System namespace (contains Console class).namespace HelloWorldApp→ Declares a namespace to organize code.class Program→ Defines a class.static void Main(string[] args)→ Entry point of the application.Console.WriteLine()→ Prints text to the console.
Summary of Chapter 1:
- C# is a modern, versatile, object-oriented language.
- It runs on the .NET platform and supports cross-platform development.
- Applications include Web, Desktop, Mobile, Games, and Cloud.
- Environment setup can be done with Visual Studio or VS Code.
- Your first “Hello World” program introduces namespaces, classes, methods, and console output.