📘 Title: Mastering C# - From Beginner to Pro
🧭 Table of Contents
1. Introduction to C#
2. Setting Up the Development Environment
3. Variables, Data Types, and Operators
4. Control Flow: Conditionals and Loops
5. Methods and Parameters
6. Object-Oriented Programming (OOP)
o Classes & Objects
o Inheritance
o Polymorphism
o Encapsulation
7. Collections and Generics
8. Exception Handling
9. File I/O and Streams
10.LINQ (Language Integrated Query)
11.Working with Asynchronous Code (async/await)
12.Windows Forms and WPF (GUI Applications)
13.Working with Databases (ADO.NET & Entity Framework)
14.Unit Testing and Debugging
15.Deploying a C# Application
16.Best Practices and Design Patterns
17.Advanced Topics (Reflection, Attributes, Dynamic Types)
18.C# for Web Development (.NET Core, ASP.NET)
19.Building APIs in C#
20.Final Project: Building a Complete App
📖 Chapter 1: Introduction to C#
What is C#?
C# (pronounced "C-sharp") is a modern, object-oriented programming language
developed by Microsoft. It runs on the .NET platform and is used for a wide range
of applications, from web development to game development (via Unity), desktop
apps, cloud services, and more.
Why Learn C#?
Strong support from Microsoft and the community
Cross-platform with .NET Core / .NET 6+
Used in game dev (Unity), web (ASP.NET), desktop (WinForms/WPF), cloud
(Azure)
Clean and readable syntax
Powerful libraries and frameworks
History of C#
Developed by Anders Hejlsberg at Microsoft
Released in 2000 with the first version of the .NET Framework
Continuously updated; current versions support modern features like pattern
matching, records, async streams, and more.
Key Features
Strongly typed: Variables must have a defined type
Object-oriented: Everything revolves around objects and classes
Type-safe: Prevents type errors at runtime
Rich library support: Extensive .NET libraries
Cross-platform: .NET Core/.NET 5+ allows running on Windows, Linux,
macOS
First C# Program: Hello World
Here’s a simple C# console application:
csharp
Sao chépChỉnh sửa
using System;
class Program
{
static void Main()
{
Console.WriteLine("Hello, World!");
}
}
Breakdown of Code:
using System; — imports the System namespace to use built-in functions like
Console.
class Program — defines a class named Program.
static void Main() — the entry point of the program.
Console.WriteLine("Hello, World!"); — prints text to the console.
📘 Chapter 2: Setting Up the Development Environment
Before writing C# programs, you need to set up your development environment.
This chapter walks you through installing the tools and creating your first C#
project.
Tools You Need
1. .NET SDK
The Software Development Kit (SDK) allows you to compile and run C#
applications.
Download from: https://dotnet.microsoft.com/download
✅ Install the latest LTS version (e.g., .NET 8)
2. IDE (Integrated Development Environment)
Option A: Visual Studio (Windows)
Most complete IDE for C#
Includes debugging, code suggestions, GUI designers
Download: https://visualstudio.microsoft.com
Choose the “Community Edition” (free)
During installation, select “.NET desktop development”
Option B: Visual Studio Code (Cross-platform)
Lightweight, fast
Add the C# Extension from Microsoft
Install: https://code.visualstudio.com
✅ Verifying Installation
Open a terminal or command prompt and run:
bash
Sao chépChỉnh sửa
dotnet --version
If it returns a version number, the .NET SDK is installed correctly.
🧪 Creating Your First Project
Step 1: Open Terminal (or CMD/PowerShell)
Navigate to a folder where you want your project:
bash
Sao chépChỉnh sửa
cd path/to/your/folder
Step 2: Create a Console App
bash
Sao chépChỉnh sửa
dotnet new console -n HelloWorldApp
This creates a folder called HelloWorldApp with a simple C# program.
Step 3: Run the Program
bash
Sao chépChỉnh sửa
cd HelloWorldApp
dotnet run
✅ You should see:
Sao chépChỉnh sửa
Hello, World!
🧰 Folder Structure Explained
bash
Sao chépChỉnh sửa
HelloWorldApp/
│
├── Program.cs # Your main C# source file
├── HelloWorldApp.csproj # Project configuration file
🧑💻 Tip: Using Visual Studio
If you’re using Visual Studio:
Open the .sln or .csproj file
Press F5 to run the program
Use the Solution Explorer to browse files