C# Programming Introduction

What Is C#?
C# (pronounced “C sharp”) is a modern, multi-paradigm programming language from Microsoft. It is type-safe, object-oriented, and runs on .NET—used for web APIs, desktop apps, games (Unity), cloud services, and mobile apps.
C# program shape:
using System;
class Program {
static void Main() { ... }
}
Runs on: .NET (cross-platform)
Created: 2000 by Anders Hejlsberg / Microsoft
Style: compiled, managed, object-oriented The C# compiler (Roslyn) and .NET runtime are open source under the .NET Foundation. This page is the gateway to the C# tutorial—practice topics such as strings, patterns, and interview programs have their own pages.
Why Learn C#?
C# pairs clear syntax with a large ecosystem. It is a strong first language and a practical choice for professional .NET work.
| Reason | What you gain |
|---|---|
| Beginner-friendly | Clear syntax, helpful compiler errors, and great tooling (VS / VS Code) |
| One language, many apps | Web, desktop, games, cloud, and mobile share the same C# skills |
| Modern features | LINQ, async/await, properties, and a rich standard library |
| Cross-platform | .NET runs on Windows, Linux, and macOS |
Short history
| Milestone | Year | Notes |
|---|---|---|
| C# 1.0 | 2000–2002 | Designed by Anders Hejlsberg; shipped with .NET Framework |
| .NET Core | 2016 | Cross-platform, open-source runtime |
| .NET 5+ | 2020+ | Unified platform; C# keeps evolving with new language versions |
| Roslyn | — | Open-source C# / VB compilers used by modern .NET |
How a C# Program Is Structured
Console apps start in Main (or top-level statements in modern templates). Learn these parts once and reuse them everywhere.
| Part | Role |
|---|---|
using System; | Imports namespaces so you can use Console without a long name |
class Program | A type that holds your methods (entry point lives here in classic style) |
static void Main() | Program entry point — .NET starts here |
Console.WriteLine(...) | Writes a line of text to the console |
Statements ending in ; | Each instruction needs a semicolon |
Cheat sheet — first syntax
| Goal | Pattern |
|---|---|
| Print text | Console.WriteLine("Hello"); |
| Integer variable | int age = 20; |
| Read a line | string? line = Console.ReadLine(); |
| Parse an int | int.TryParse(line, out int n) |
| Condition | if (x > 0) { ... } |
| Counted loop | for (int i = 0; i < n; i++) { ... } |
Your First C# Program — Hello World
Classic console style with an explicit Main method. Put this in Program.cs (or replace the template content).
using System;
class Program
{
static void Main()
{
Console.WriteLine("Hello, World!");
}
} How It Works
1. Import System. using System; lets you write Console instead of System.Console.
2. Enter Main. .NET calls Main when the program starts.
3. Print. Console.WriteLine writes the string and a newline to the console.
How to Create and Run a Console App
Install the .NET SDK, then use the dotnet CLI. You do not need Visual Studio to get started.
dotnet new console -n HelloApp
cd HelloApp
dotnet run | Command | Meaning |
|---|---|
dotnet new console | Create a new console project |
dotnet run | Build and run the current project |
dotnet build | Compile without running |
dotnet --version | Check that the SDK is installed |
Modern templates may use top-level statements (no explicit Main). The idea is the same: statements run from top to bottom when you call dotnet run.
Core Building Blocks
You do not need to master everything today. This map shows the main ideas you will meet as you continue with C#.
| Concept | What it does |
|---|---|
| Variables & types | Store data (int, string, bool, …) |
| Operators | Arithmetic, comparison, and logical operations |
| Control flow | if, else, switch for decisions |
| Loops | for, while, foreach for repetition |
| Methods | Reusable blocks with parameters and return values |
| Strings | Text data and common string methods |
| Classes & objects | Group data and behavior in custom types |
| Collections & LINQ | Lists, dictionaries, and query-style operations |
Where Is C# Used?
Common places you will see C# in the real world:
| Use case | Why C# fits |
|---|---|
| Web APIs & ASP.NET | Strong framework support for backends and services |
| Desktop apps | WPF, WinForms, and cross-platform UI options |
| Games (Unity) | Unity’s primary scripting language is C# |
| Cloud & Azure | First-class tooling for Microsoft cloud services |
| Mobile (.NET MAUI) | Share C# code across Android and iOS |
| Learning & interviews | Patterns and classic programs build problem-solving skill |
Key Takeaways
- C# is a modern, object-oriented language that runs on .NET.
- Shape:
using+ class +Main+Console.WriteLine. - Run:
dotnet new console, thendotnet run. - Next: practice strings and pattern programs to build fluency.
One line: write Main, print with Console.WriteLine, run with dotnet run — then practice with star patterns.
Frequently Asked Questions
Did you know?
C# runs on .NET. Start a console app with dotnet new console, then dotnet run. The compiler (Roslyn) and runtime are open source under the .NET Foundation.
Next: C# Star Patterns
Turn nested loops into clear, printable patterns — a great next practice step.
12 people found this page helpful
