How to use this topic

The first seven pages cover the basics: what C# and .NET are, the dotnet command and your first program, types and operators, strings, control flow and pattern matching, loops and methods. The next eight are about types and data: collections, classes, records and structs, inheritance and interfaces, null safety, exceptions, generics, and delegates and lambdas. The last five show the features that make C# productive in practice: LINQ, async and await, files and JSON, projects and NuGet, and testing.

Every example is a complete program that runs with dotnet run and shows its exact output. General programming ideas are explained in Programming Concepts; where C# differs from Python or JavaScript, the pages say so.

The basic pages are tagged Foundational C#: they cover the material of Foundational C# with Microsoft, a free certification by freeCodeCamp and Microsoft.

Learning path

  1. 01What Is C# and .NET?What C# is and the platform it runs on: a short history, the difference between .NET Framework and modern .NET, how code is compiled and run, version support, and where C# is used.BeginnerFoundational C#
  2. 02The .NET SDK, the dotnet CLI and Your First ProgramGetting started with C#: installing the .NET SDK, the dotnet command, running a single file, top-level statements, reading input and writing output, and what a project adds.BeginnerFoundational C#
  3. 03Variables, Types and OperatorsHow C# stores data: declaring variables, the built-in types, value types and reference types, var and const, conversions and casts, and the arithmetic, comparison and logical operators.BeginnerFoundational C#
  4. 04Strings and String InterpolationWorking with text in C#: string literals and escapes, interpolation with $ and format specifiers, verbatim and raw string literals, common string methods, StringBuilder, and culture-aware formatting.BeginnerFoundational C#
  5. 05Control Flow and Pattern MatchingMaking decisions in C#: if and else, the switch statement and switch expressions, and patterns that test types, values, ranges and shapes in one readable expression.BeginnerFoundational C#
  6. 06LoopsRepeating work in C#: for, foreach, while and do-while loops, break and continue, looping over collections safely, and when a LINQ query is the clearer choice.BeginnerFoundational C#
  7. 07Methods and ParametersWriting reusable code in C#: methods with parameters and return values, overloading, optional and named arguments, params, ref, out and in parameters, local functions and expression-bodied members.BeginnerFoundational C#
  8. 08Arrays, Lists and CollectionsStoring groups of values in C#: arrays, List<T>, Dictionary<TKey,TValue> and HashSet<T>, collection expressions, indexes and ranges, and choosing the right collection.BeginnerFoundational C#
  9. 09Classes and ObjectsObject-oriented C#: classes with fields, properties and methods, constructors and primary constructors, object initializers, required and init-only properties, and static members.Beginner
  10. 10Records, Structs and EnumsOther kinds of types in C#: records with value equality and with-expressions, structs as value types, enums for named constants, and when to choose which.Intermediate
  11. 11Inheritance, Interfaces and PolymorphismBuilding on other types in C#: base and derived classes, virtual and override, abstract and sealed classes, interfaces, and polymorphism, with advice on when composition is better.Intermediate
  12. 12Nullable Reference Types and Null SafetyAvoiding NullReferenceException in C#: nullable value types, nullable reference types and compiler warnings, the ?., ?? and ??= operators, the null-forgiving operator, and patterns for checking null.Intermediate
  13. 13Exceptions and Error HandlingWhen things go wrong in C#: reading an exception, try, catch and finally, exception filters, throwing your own exceptions, using to clean up resources, and when not to use exceptions.BeginnerFoundational C#
  14. 14GenericsWriting type-safe code that works for many types in C#: generic methods and classes, type parameters and constraints, and how the generic collections you already use work.Intermediate
  15. 15Delegates, Lambdas and EventsTreating code as data in C#: delegates, the Func and Action types, lambda expressions and closures, and events for notifying other code.Intermediate
  16. 16LINQQuerying collections in C# with Language Integrated Query: filtering, projecting, sorting, grouping and aggregating with methods such as Where and Select, query syntax, and deferred execution.Intermediate
  17. 17Asynchronous Programming with async and awaitWaiting without blocking in C#: Task and Task<T>, async methods and await, running work in parallel with Task.WhenAll, cancellation and timeouts, and the common mistakes.Intermediate
  18. 18Files, JSON and the .NET LibrariesGetting real work done with the .NET libraries: reading and writing files and paths, JSON with System.Text.Json, dates and times, and where to find the rest of the base class library.Intermediate
  19. 19Projects, NuGet and BuildingFrom a single file to a real application: the project file, solutions, NuGet packages and versions, building, publishing self-contained and native AOT apps, and keeping dependencies up to date.Intermediate
  20. 20Testing and Code QualityKeeping C# code correct and maintainable: unit tests with xUnit, dotnet test, the built-in analyzers, nullable warnings as errors, EditorConfig and dotnet format, and naming conventions.Intermediate

C# glossary

Short definitions of the terms used in this topic. The full glossary covers every topic.