This page is a self-contained introduction to C# (pronounced “C sharp”)—no prior coding experience required. You will understand what C# is, write your first console program, and learn how .NET runs your code.
01
What is C#
Modern .NET lang.
02
History
Microsoft & .NET.
03
Hello World
First program.
04
dotnet run
Run locally.
05
Open source
Roslyn compiler.
06
Building blocks
Core concepts.
Fundamentals
🤔 What is C# Programming?
C# is a modern, multi-paradigm programming language developed by Microsoft. It is designed to be simple, efficient, and type-safe. Developers use it to build Windows desktop apps, web APIs with ASP.NET, cloud services on Azure, games with Unity, and cross-platform mobile apps with .NET MAUI.
C# is an object-oriented language. You organize code into classes and objects, which makes large applications easier to maintain, test, and extend. The .NET runtime manages memory for you through garbage collection, so you focus on logic rather than manual allocation.
💡
Beginner tip
Start with small console programs using Console.WriteLine and if/for. Once those feel natural, move on to classes, lists, and async code.
Background
👤 Who Created C#?
Anders Hejlsberg is widely considered the father of C#. The Danish computer scientist led the team at Microsoft that designed C# in the late 1990s, with the first release shipping alongside .NET in the early 2000s. The goal was a modern, object-oriented language for the Microsoft ecosystem that felt familiar to C++ and Java developers.
Since then, C# has evolved through many versions with generics, LINQ, async/await, records, and more. The timeline below highlights major milestones.
Version / Event
Year
Highlight
C# announced
2000
Anders Hejlsberg, Microsoft
C# 1.0 + .NET 1.0
2002
First public release
C# 2.0
2005
Generics, nullable types
C# 3.0
2007
LINQ, lambda expressions
C# 5.0
2012
async / await
Roslyn open source
2014
Compiler on GitHub
.NET Core
2016
Cross-platform .NET
C# 9.0
2020
Records, top-level statements
C# 12
2023
Primary constructors, collection expressions
Platform
🔓 Is C# Open Source?
Yes. C# and .NET are open source. The Roslyn compiler, large parts of the runtime, and the base class libraries are available on GitHub under permissive licenses (MIT and similar). Developers can use, study, modify, and contribute to the platform freely.
You do not need Windows to write C# today—install the .NET SDK on Linux, macOS, or Windows and use VS Code, Visual Studio, or JetBrains Rider.
Foundation
📝 Program Structure & Syntax
A classic C# console program includes a using directive, a class, and a Main method as the entry point:
C#
using System;
class HelloWorld
{
static void Main(string[] args)
{
Console.WriteLine("Hello, World!");
}
}
Syntax rules
using System; — imports the System namespace so you can use Console and other core types.
class — defines a type that groups methods and data (object-oriented design).
static void Main — entry point; the runtime calls this method when the program starts.
Console.WriteLine — prints a line of text to the terminal.
Semicolons — end statements; braces { } define blocks.
Top-level statements — newer templates allow shorter Program.cs without an explicit class; both styles are valid.
Toolchain
💻 How to Create and Run a C# Program
Install the .NET SDK, then create a console project from a terminal:
C#
dotnet new console -n HelloApp
cd HelloApp
dotnet run
dotnet new console — scaffolds a project with Program.cs and a .csproj file.
dotnet run — compiles and executes in one step (great while learning).
dotnet build — compile only; useful before deployment.
IDEs — Visual Studio, VS Code with C# Dev Kit, or JetBrains Rider provide IntelliSense and debugging.
Concepts
🧰 Core Building Blocks
As you continue learning C#, these are the main ideas you will encounter:
Concept
What it does
Types & variables
int, double, string, bool, and more
Control flow
if, else, switch, loops
Methods
Reusable functions inside classes
Classes & objects
Encapsulate data and behavior (OOP)
Properties
Clean getters/setters for fields
Collections
List<T>, arrays, dictionaries
LINQ
Query collections with readable syntax
async / await
Non-blocking I/O and responsive apps
Cheat Sheet
⚡ Quick Reference
Task
Example
Print line
Console.WriteLine("Hi");
Read line
string s = Console.ReadLine();
Parse integer
int n = int.Parse(input);
Condition
if (x > 0) { ... }
for loop
for (int i = 0; i < n; i++) { ... }
String interpolate
$"Age: {age}"
Hands-On
Examples Gallery
Five starter console programs. Create a project with dotnet new console, paste into Program.cs (adjust class structure if needed), and run with dotnet run.
Example 1 — Hello, World!
C#
using System;
class HelloWorld
{
static void Main(string[] args)
{
Console.WriteLine("Hello, World!");
}
}
Console.WriteLine() outputs text. Main() is where execution begins. using System; imports core types including Console.
📤 Output:
Hello, World!
Example 2 — Variables and output
C#
using System;
class Vars
{
static void Main()
{
int age = 20;
double gpa = 3.85;
char grade = 'A';
string name = "Alex";
Console.WriteLine($"Name: {name}");
Console.WriteLine($"Age: {age}");
Console.WriteLine($"GPA: {gpa:F2}");
Console.WriteLine($"Grade: {grade}");
}
}
📤 Output:
Name: Alex
Age: 20
GPA: 3.85
Grade: A
Example 3 — Reading user input
C#
using System;
class InputDemo
{
static void Main()
{
Console.Write("Enter a number: ");
string text = Console.ReadLine();
int num = int.Parse(text);
Console.WriteLine($"You entered: {num}");
}
}
📤 Output (sample run):
Enter a number: 42
You entered: 42
In production code, prefer int.TryParse to handle invalid input safely.
Example 4 — A simple method
C#
using System;
class AddDemo
{
static int Add(int a, int b)
{
return a + b;
}
static void Main()
{
Console.WriteLine($"Sum = {Add(3, 5)}");
}
}
📤 Output:
Sum = 8
Example 5 — Even or odd with if-else
C#
using System;
class EvenOdd
{
static void Main()
{
Console.Write("Enter n: ");
int n = int.Parse(Console.ReadLine());
if (n % 2 == 0)
Console.WriteLine($"{n} is even");
else
Console.WriteLine($"{n} is odd");
}
}
📤 Output (sample run):
Enter n: 7
7 is odd
Motivation
📚 Why Learn C#?
Versatile career path — web, desktop, games, cloud, and enterprise backends.
Strong tooling — IntelliSense, debugging, and NuGet packages speed up development.
Type safety — catch many errors at compile time before users see them.
Modern language — regular updates add productivity features without breaking the ecosystem.
Cross-platform .NET — deploy the same skills on Windows, Linux, and macOS.
Unity & games — one of the most popular languages for indie and AAA game scripting.
Compare
📋 C# vs Other Languages
Language
Runtime
Best for beginners when…
C#
.NET (CLR)
You want OOP, tooling, and Microsoft/Azure ecosystem skills
Java
JVM
You target Android or enterprise JVM stacks
Python
Interpreter
You want the fastest path to scripts and data science
C++
Native
You need maximum performance and systems control
🧠 How a C# Program Runs
1
Write C# source (.cs)
You create classes, methods, and a Main entry point (or top-level statements).
Edit
2
Compile to IL
Roslyn compiles C# to Intermediate Language (IL) packaged in an assembly.
Compile
3
CLR executes
The .NET runtime (CLR) JIT-compiles IL to native code and manages memory.
Runtime
=
▶️
Output appears
Main runs; Console.WriteLine prints to the terminal.
Recap
Summary
C# (C sharp) is a modern, type-safe language created by Anders Hejlsberg at Microsoft.
It is object-oriented and runs on the cross-platform .NET runtime.
C# and Roslyn are open source with an active community.
Programs use using, classes, Main, and Console for basic I/O.
Run locally with dotnet new console and dotnet run.
The # symbol is the “sharp” in the name—like musical notation for a half-step higher.
Pro Tips
💡 Best Practices
✅ Do
Use meaningful names (studentCount, not x)
Prefer int.TryParse over bare int.Parse for user input
Brace every if and loop body for clarity
Run dotnet build and fix warnings early
Type out examples yourself—muscle memory matters
Read compiler errors from the first line downward
❌ Don’t
Ignore null reference warnings in modern C# projects
Compare strings with == when culture matters (use Equals with options)
Put all logic inside Main forever—split into methods and classes
Skip understanding basic OOP before frameworks like ASP.NET
Copy code without knowing what each line does
Assume C# only runs on Windows—.NET is cross-platform
❓ Frequently Asked Questions
C# (pronounced "C sharp") is a modern, multi-paradigm language from Microsoft. It is type-safe, object-oriented, and runs on .NET. Developers use it for web APIs, desktop apps, games with Unity, cloud services, and mobile apps with .NET MAUI.
Yes. C# has clear syntax, helpful compiler messages, and strong tooling in Visual Studio and VS Code. It teaches object-oriented concepts while staying approachable. Many schools and bootcamps use C# for first-year programming courses.
Install the .NET SDK, then run: dotnet new console -n HelloApp, cd HelloApp, dotnet run. Paste the hello world code into Program.cs. You can also use online C# runners if you cannot install the SDK yet.
Yes. The C# compiler (Roslyn), the .NET runtime, and much of the platform are open source under permissive licenses. Microsoft and the community maintain them on GitHub through the .NET Foundation.
Practice variables, if-else, loops, and methods in small console programs. Then learn classes and objects, collections, exception handling, and LINQ. Build habits early: use meaningful names, handle parse errors, and read compiler messages carefully.
Both are object-oriented and run on managed runtimes (.NET vs JVM). C# integrates tightly with Windows and Azure but is cross-platform via .NET. Syntax is similar; C# adds features like properties, LINQ, and async/await with slightly different keywords.
Did you know?
The # symbol in C# is the musical “sharp” sign—raising a note by a half step. That is how the language got its name: C raised one step, suggesting an evolution beyond C and C++. If you know C-style syntax, many C# basics will feel familiar on day one.