C# Tutorial
C# (pronounced "C sharp") is a modern, friendly language made by Microsoft. It's used to build Windows apps, websites with ASP.NET, mobile apps, and games with Unity, the engine behind countless mobile and indie games. If you want to make games, C# is one of the best languages to learn.
This free course has 15 lessons. Every example is a complete program with its output, followed by a Taglish summary and a quick quiz.
How to run the examples
- On a computer: install the free .NET SDK and VS Code, or Visual Studio Community. Lesson 2 shows how.
- On a phone: use an online C# compiler, such as .NET Fiddle.
Before you start
No experience is needed. C# looks very similar to Java, so if you've taken our Java course, you'll recognize most of the syntax.
What you'll be able to do
- Write and run C# console programs
- Read input, make decisions and repeat tasks with loops
- Store data in arrays, Lists and Dictionaries
- Write methods and design classes with properties
- Query data with LINQ and handle errors with exceptions
- Build a complete student enrollment system
All lessons
Getting Started
- Introduction to C#What C# is, what .NET is, where C# is used (Unity games, Windows apps, websites), and what a first C# program looks like.
- Getting Started with C# — Install .NET and Run a ProgramInstall the .NET SDK, create a console app with dotnet new console, run it with dotnet run, use Visual Studio or VS Code, and read compiler errors.
- C# Output and Input — WriteLine, ReadLine and String InterpolationPrint with Console.WriteLine and Write, build messages with string interpolation, format numbers, read input with Console.ReadLine, and convert it with int.Parse and TryParse.
Basics
- C# Variables and Data TypesDeclare C# variables with int, double, decimal, bool, char and string, use var, const and readonly, understand nullable types, and convert between types with casting and Convert.
- C# Operators and the Math ClassArithmetic, assignment, comparison and logical operators in C#, increment and decrement, the Math class (Pow, Sqrt, Round, Max), and random numbers with Random.
- C# Strings and String MethodsWork with text in C# — Length, indexing, ToUpper, Trim, Substring, IndexOf, Replace, Split, Contains, comparison, verbatim strings and StringBuilder.
Control Flow
- C# if, else, switch and Switch ExpressionsMake decisions in C# with if, else if, else, the switch statement, modern switch expressions with patterns, and the ternary operator.
- C# Loops — for, foreach, while and do-whileRepeat code in C# with for, foreach, while and do-while loops, use break and continue, validate input in a loop, and build nested patterns.
Collections & Methods
- C# Arrays, Lists and DictionariesStore many values in C# arrays, the resizable List<T>, and key–value Dictionary<TKey, TValue> — add, remove, search, sort and loop through them.
- C# Methods — Parameters, Return Values, ref and outWrite reusable C# methods with parameters and return values, use optional and named arguments, overload methods, return several values with tuples, and use ref and out.
Object-Oriented Programming
- C# Classes, Objects, Properties and ConstructorsDesign C# classes with fields, properties, constructors and methods, create objects with new, protect data with private fields and validated properties, and use records.
- C# Inheritance, Polymorphism and InterfacesBuild classes on others with inheritance and base, override virtual methods, use abstract classes and interfaces, and treat different objects the same way with polymorphism.
Going Further
- C# LINQ — Querying CollectionsFilter, sort, transform and summarize collections with LINQ — Where, Select, OrderBy, First, Any, Count, Sum, Average, GroupBy — using lambdas, with class record examples.
- C# Exceptions and File HandlingHandle errors with try, catch, finally and throw, know common exceptions, and read and write text files with File.WriteAllLines, File.ReadAllLines and File.AppendAllText.
- C# Final Project — Student Enrollment SystemBuild a complete console enrollment system in C# with records, a List and Dictionary, a menu, input validation, LINQ reports and saving to a CSV file.