🔔 C# — Learn From Zero

Playground: Replit C# | .NET Fiddle — click, type, run.

What is C#?

C# is a modern, object-oriented language by Microsoft on .NET. Great for desktop, web (ASP.NET), games (Unity), and cloud.

  • Web APIs (ASP.NET Core)
  • Games (Unity)
  • Desktop (WPF, MAUI)
  • Cloud services

Run Online — No Install

Use the playground links above.

🟢 Beginner — Core Basics

Your First Program

csharp
using System;
class Program {
  static void Main() {
    Console.WriteLine("Hello, world!");
  }
}

Entry point is Main().

Variables & Types

csharp
int age = 36;
double height = 1.78;
bool isStudent = true;
string name = "Ada";

Types: int, double, bool, string.

If / Else

csharp
int age = 18;
if (age >= 18) Console.WriteLine("Vote");
else Console.WriteLine("Too young");

Curly braces group statements.

Loops

csharp
for (int i = 0; i < 5; i++) Console.WriteLine(i);

Also foreach for collections.

Methods

csharp
static int Add(int a, int b) => a + b;

Expression-bodied methods are concise.

Arrays & Lists

csharp
string[] fruits = {"apple", "banana"};
var list = new List { 1, 2, 3 };

Prefer List<T> over arrays.

🟡 Intermediate — Building Real Programs

Classes & Objects

csharp
class Person {
  public string Name { get; set; }
  public int Age;
}

Properties use get; set;.

OOP

csharp
interface IAnimal { void Speak(); }
class Dog : IAnimal { public void Speak() {} }

Inheritance & interfaces.

LINQ

csharp
var nums = new[] {1,2,3,4};
var even = nums.Where(n => n % 2 == 0);

Query collections declaratively.

async/await

csharp
async Task Load() {
  using var c = new HttpClient();
  return await c.GetStringAsync("url");
}

Await async operations.

Exceptions

csharp
try { int x = 1/0; }
catch (DivideByZeroException) { }

Use try/catch.

🔴 Advanced — Pro Concepts

Generics

csharp
class Box {
  public T Value { get; set; }
}

Type-safe containers.

Records

csharp
record Point(int X, int Y);
var p = new Point(1, 2);

Immutable value types.

Pattern Matching

csharp
string msg = o switch {
  int i => $"int {i}",
  _ => "other"
};

Powerful switch expressions.

Task Parallelism

csharp
Parallel.For(0, 10, i => Console.WriteLine(i));

Data parallelism with TPL.

What's Next?

  • Build a tiny project: Calculator, To-Do App, Weather Widget
  • Read the official docs and a good book
  • Solve Exercism exercises
  • Join a community & share your code

Practice daily for 20 minutes. Consistency > intensity.