Introduction to C#
Learn the fundamentals of C# programming and understand why C# is one of the most widely used programming languages for modern application development.
What is C#?
C# (C-Sharp) is a popular, modern programming language made by Microsoft. It is designed to be safe, easy to read, and powerful.
Think of C# as the written language (like English). You use it to write instructions that tell a computer what to do. Today, C# is completely free and cross-platform, meaning you can use it to build apps for Windows, Mac, Linux, iPhones, and Android phones.
C# is a general-purpose programming language. It can be used to build many different types of applications such as web applications, desktop applications, APIs, cloud applications, games, and enterprise software.
C# is also a cross-platform language. This means that modern C# applications can run on Windows, macOS, and Linux using the .NET platform.
C# was developed by Microsoft and is mainly used together with the .NET platform.
Why Learn C#?
Modern Language
C# provides modern programming features that make application development easier, cleaner, and more productive.
Object-Oriented
C# supports classes, objects, inheritance, polymorphism, abstraction, and encapsulation.
Cross-Platform
Modern .NET applications can run on Windows, macOS, and Linux.
Automatic Memory Management
C# applications use garbage collection to automatically manage unused objects and memory.
Key Features of C#
- Simple and easy to learn
- Object-oriented
- Type-safe
- Cross-platform
- Secure
- Modern and powerful
- Supports asynchronous programming
- Automatic garbage collection
- High performance with JIT compilation
The .NET Ecosystem
If C# is the language, .NET is the entire toolset and workshop where you use that language. .NET provides the environment, tools, and libraries required to build and run C# applications.
Over the years, .NET has evolved.
Old Way (.NET Framework): It was primarily designed to work on Windows computers.
Modern Way (.NET Core / Modern .NET): Modern .NET is cross-platform and works on Windows, macOS, and Linux.
When you install the .NET platform, you work with several important components.
| Component | Description |
|---|---|
| SDK | Software Development Kit provides the tools required to create, build, test, and develop .NET applications. |
| Runtime | The .NET Runtime provides the environment required to execute .NET applications. |
| Libraries | .NET libraries contain reusable classes, methods, and functions that help developers perform common programming tasks. |
| CLR | Common Language Runtime manages the execution of .NET applications and provides services such as memory management and exception handling. |
How C# Works
A C# source file normally has the
.cs extension.
When we build a C# application, the C# compiler converts
the source code into Intermediate Language (IL).
C# Source Code
↓
C# Compiler
↓
Intermediate Language (IL)
↓
CLR
↓
JIT Compiler
↓
Machine Code
↓
Operating System / Hardware
The CLR manages the execution of the application. The JIT (Just-In-Time) compiler converts the Intermediate Language into machine instructions that the computer can execute.
This process allows modern .NET applications to run on different operating systems.
The Common Language Runtime (CLR)
The Common Language Runtime (CLR) is one of the most important parts of the .NET platform. It manages the execution of C# programs while they are running.
When you run a C# program, it does not instantly talk to the computer's processor. Instead, it goes through a two-step process.
Step 1: The .NET tools translate your C# code into a middle-ground language called Intermediate Language (IL). This is a universal code that can be moved to any computer.
Step 2: When the application runs, the CLR takes that universal code and uses the JIT (Just-In-Time) Compiler to translate it into machine code that your computer understands.
What Does the CLR Do?
While your program is running, the CLR watches over it and provides several services that help the application run safely and efficiently.
Garbage Collection
It automatically cleans up unused memory so the application can use memory efficiently.
Exception Handling
It provides mechanisms for handling errors and unexpected situations during program execution.
JIT Compilation
The JIT compiler converts Intermediate Language into machine code when the application runs.
Program Management
The CLR manages important aspects of program execution and provides services required by .NET applications.
Simple C# Program
Let's look at a simple C# program that prints a message on the console.
using System;
class Program
{
static void Main()
{
Console.WriteLine("WelCome CIIT Institute🤓");
}
}
Understanding the Program
| Code | Purpose |
|---|---|
using System;
|
Imports the System namespace so we can use classes such as Console. |
class Program
|
Defines a class named Program. |
static void Main()
|
Defines the main method where execution of the program begins. |
Console.WriteLine()
|
Displays text on the console. |
Where is C# Used?
- Web application development
- Backend and API development
- Desktop application development
- Enterprise applications
- Cloud applications
- Game development using Unity
- Windows application development
- Microservices and distributed applications
CIIT Practical Learning
At CIIT Institute, C# is learned step-by-step with practical coding examples. Students can start with programming fundamentals and gradually move toward real-world application development using .NET.
Summary
C# is a modern, powerful, object-oriented programming language developed by Microsoft. It works with the .NET platform and can be used to build web applications, APIs, desktop applications, cloud solutions, games, and enterprise software. Understanding C#, .NET, CLR, JIT compilation, and basic program structure provides a strong foundation for learning advanced C# development.