C# Tutorial
The core language of .NET. Types, OOP, collections, LINQ, async/await and modern C# features.
- 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.
- 1Basics · 7 topics · BeginnerIntroduction to C# · Installing the .NET SDK · Variables and Data Types · Operators · Conditional Statements · Loops · Methods
- 2Data · 3 topics · BeginnerArrays and Collections · Strings · Nullable Types
- 3Object-Oriented Programming · 6 topics · Beginner → IntermediateClasses and Objects · Encapsulation · Inheritance · Polymorphism · Abstraction · Interfaces
- 4Intermediate · 8 topics · Intermediate → AdvancedException Handling · Generics · Delegates and Events · Lambda Expressions · LINQ · Async and Await · Records · Pattern Matching
- 5Practice · 2 topics · AdvancedUnit Testing with xUnit · Interview Questions
Complete topic list
26 topicsBasics
7 topics- Introduction to C#Beginner5m
- Installing the .NET SDKBeginner5m
- Variables and Data TypesBeginner5m
- OperatorsBeginner5m
- Conditional StatementsBeginner5m
- LoopsBeginner5m
- MethodsBeginner6m
Data
3 topics- Arrays and CollectionsBeginner5m
- StringsBeginner5m
- Nullable TypesBeginner5m
Object-Oriented Programming
6 topics- Classes and ObjectsBeginner6m
- EncapsulationBeginner6m
- InheritanceIntermediate6m
- PolymorphismIntermediate5m
- AbstractionIntermediate5m
- InterfacesIntermediate5m
Intermediate
8 topics- Exception HandlingIntermediate6m
- GenericsIntermediate6m
- Delegates and EventsIntermediate6m
- Lambda ExpressionsIntermediate6m
- LINQAdvanced5m
- Async and AwaitAdvanced6m
- RecordsAdvanced5m
- Pattern MatchingAdvanced6m
Practice
2 topics- Unit Testing with xUnitAdvanced6m
- Interview QuestionsAdvanced15m
Code example
A taste of the track, from Introduction to C#.
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}.");
Hello, C#! Asha has 24 lessons to learn. Half way is lesson 12.
Practice exercises
Write a program that stores your name and your age in two variables and prints: "My name is ___ and next year I will be ___."
Create a console app called Greeter, change Program.cs so it prints "Setup complete!", and run it.
Store a product name, its unit price (decimal) and a quantity (int). Print the total price with 2 decimal places.
Given int minutes = 135, print it as hours and minutes: "2 h 15 min".
Write a switch expression that turns a number 1–7 into the day name (1 = "Mon") and returns "Invalid" for anything else.
Print the even numbers from 1 to 20 using a for loop and continue.
Show all 25 exercises
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.
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.
Given string fullName = " ravi KUMAR ", print it as "Ravi Kumar" (trimmed, each word capitalised).
Write a method GetDisplayName(string? nickname, string fullName) that returns the nickname when it is not null or empty, otherwise the full name.
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.
Create a Temperature class with a Celsius property that rejects values below -273.15, and a read-only Fahrenheit property calculated from Celsius.
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)".
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.
Create an abstract class Shape with an abstract double Area() and a normal method Describe() returning "Area: X" (2 decimals). Implement Circle and Square.
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.
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.
Write a generic method Swap<T>(ref T a, ref T b) that swaps two values, and test it with ints and strings.
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.
Given List<string> names = ["Asha", "Ravi", "Meera", "Kabir"], use FindAll with a lambda to keep names longer than 4 letters, then print them.
Return the names of all Angular students in alphabetical order.
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.
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.
Write a switch expression that returns a ticket price by age: under 5 → 0, 5–17 → 100, 60 and over → 120, everyone else → 200.
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
- What is the difference between value types and reference types?
- What is the difference between const and readonly?
- What are nullable reference types?
- String vs StringBuilder?
- What is the difference between C#, .NET and the CLR?
- What are top-level statements?
- What does var mean in C#?
- What is the difference between == and Equals for strings and objects?
- for vs foreach vs while?
- What are ref, out and in parameters?
- Array vs List<T> vs Dictionary<TKey, TValue>?
- What is deferred execution in LINQ?
- What are delegates and events?
- What are records?
- IEnumerable vs IQueryable?
- How does exception handling work, and what does finally do?
- What are generics and why are they better than object?
- What is a lambda expression?
- What is an interface in C# and what can it contain?
- What is boxing and unboxing?
- How do you write unit tests in C#?
- Why should you avoid .Result and .Wait() on tasks?
- What is pattern matching in modern C#?
- Task vs ValueTask, and what does async void risk?
- How does garbage collection work in .NET?
- What is IDisposable and the dispose pattern?
- How do you run several async operations in parallel?
- What are extension methods?