.NET track

C# Tutorial

The core language of .NET. Types, OOP, collections, LINQ, async/await and modern C# features.

BeginnerExamples target C# 13 on .NET 9 unless stated otherwise.
0/26 complete
Topics
26
Full lessons
26
Est. hours
~5
Interview Qs
28

Overview

C# is a modern, type-safe, object-oriented language that runs on .NET. It is used for web APIs, desktop apps, cloud services and games.

This track gives you the language foundation every ASP.NET, Web API and Blazor lesson builds on.

What you will learn

  • Write programs with types, control flow and methods
  • Apply OOP: classes, inheritance, interfaces and polymorphism
  • Query data with LINQ
  • Write asynchronous code with async/await

Prerequisites

None — this track starts from the very beginning.

Learning path

The recommended sequence, from beginner to advanced. Each stage builds on the one before.

  1. 1Basics · 7 topics · Beginner
    Introduction to C# · Installing the .NET SDK · Variables and Data Types · Operators · Conditional Statements · Loops · Methods
  2. 2Data · 3 topics · Beginner
    Arrays and Collections · Strings · Nullable Types
  3. 3Object-Oriented Programming · 6 topics · Beginner → Intermediate
    Classes and Objects · Encapsulation · Inheritance · Polymorphism · Abstraction · Interfaces
  4. 4Intermediate · 8 topics · Intermediate → Advanced
    Exception Handling · Generics · Delegates and Events · Lambda Expressions · LINQ · Async and Await · Records · Pattern Matching
  5. 5Practice · 2 topics · Advanced
    Unit Testing with xUnit · Interview Questions

Complete topic list

26 topics
1

Basics

7 topics
  1. Introduction to C#Beginner5m
  2. Installing the .NET SDKBeginner5m
  3. Variables and Data TypesBeginner5m
  4. OperatorsBeginner5m
  5. Conditional StatementsBeginner5m
  6. LoopsBeginner5m
  7. MethodsBeginner6m
2

Data

3 topics
  1. Arrays and CollectionsBeginner5m
  2. StringsBeginner5m
  3. Nullable TypesBeginner5m
3

Object-Oriented Programming

6 topics
  1. Classes and ObjectsBeginner6m
  2. EncapsulationBeginner6m
  3. InheritanceIntermediate6m
  4. PolymorphismIntermediate5m
  5. AbstractionIntermediate5m
  6. InterfacesIntermediate5m
4

Intermediate

8 topics
  1. Exception HandlingIntermediate6m
  2. GenericsIntermediate6m
  3. Delegates and EventsIntermediate6m
  4. Lambda ExpressionsIntermediate6m
  5. LINQAdvanced5m
  6. Async and AwaitAdvanced6m
  7. RecordsAdvanced5m
  8. Pattern MatchingAdvanced6m
5

Practice

2 topics
  1. Unit Testing with xUnitAdvanced6m
  2. Interview QuestionsAdvanced15m

Code example

A taste of the track, from Introduction to C#.

C#Program.cs Illustrative
Console.WriteLine("Hello, C#!");


string name = "Asha";
int lessons = 24;


Console.WriteLine(
quot;
{name} has {lessons} lessons to learn.");
Console.WriteLine(
quot;Half way is lesson
{lessons / 2}.");
Expected output
Hello, C#!
Asha has 24 lessons to learn.
Half way is lesson 12.

Practice exercises

Show all 25 exercises
Methods

Write a method IsEven(int n) that returns a bool, and a method Describe(int n) that returns "4 is even" or "7 is odd" using IsEven.

Arrays and Collections

Count how many times each word appears in the array ["apple", "mango", "apple", "kiwi", "apple"] using a Dictionary<string, int>, then print each word and its count.

Strings

Given string fullName = " ravi KUMAR ", print it as "Ravi Kumar" (trimmed, each word capitalised).

Nullable Types

Write a method GetDisplayName(string? nickname, string fullName) that returns the nickname when it is not null or empty, otherwise the full name.

Classes and Objects

Create a Product class with Name and Price properties, a constructor, and a method PriceWithGst() that returns the price plus 18%. Create two products and print both prices with GST.

Encapsulation

Create a Temperature class with a Celsius property that rejects values below -273.15, and a read-only Fahrenheit property calculated from Celsius.

Inheritance

Create a Vehicle class with a virtual Describe() returning "Vehicle with N wheels", and a Bike class that inherits it, passes 2 wheels to the base constructor and overrides Describe to add " (bike)".

Polymorphism

Create a base class Notification with a virtual Send() returning "Sending notification", and EmailNotification / SmsNotification that override it. Loop over a list of both and print the results.

Abstraction

Create an abstract class Shape with an abstract double Area() and a normal method Describe() returning "Area: X" (2 decimals). Implement Circle and Square.

Interfaces

Create an IDiscount interface with decimal Apply(decimal price). Implement PercentDiscount(10%) and FlatDiscount(50). Apply both to a price of 500 and print the results.

Exception Handling

Write SafeDivide(int a, int b) that returns a / b, but returns 0 and prints "Cannot divide by zero" when b is 0, by catching DivideByZeroException.

Generics

Write a generic method Swap<T>(ref T a, ref T b) that swaps two values, and test it with ints and strings.

Delegates and Events

Write a method Transform(List<string> items, Func<string, string> change) that returns a new list with change applied to every item. Call it with a method that adds "#" in front of each word.

Lambda Expressions

Given List<string> names = ["Asha", "Ravi", "Meera", "Kabir"], use FindAll with a lambda to keep names longer than 4 letters, then print them.

LINQ

Return the names of all Angular students in alphabetical order.

Async and Await

Write an async method DownloadAsync(string name, int ms) that waits ms milliseconds and returns "<name> done". Start three downloads together and print all results with Task.WhenAll.

Records

Create a record Money(decimal Amount, string Currency). Create 100 INR, make a copy with Amount 250 using with, and print both plus whether new Money(100, "INR") equals the first one.

Pattern Matching

Write a switch expression that returns a ticket price by age: under 5 → 0, 5–17 → 100, 60 and over → 120, everyone else → 200.

Unit Testing with xUnit

Write xUnit tests for a static method bool IsValidPin(string pin) that is true only for exactly 6 digits. Use a Theory with at least 4 rows.

Common interview questions

Frequently asked questions

Is C# only for Windows?
No. Modern .NET is cross-platform and runs on Windows, Linux and macOS.