This C# tutorial helps you learn C# programming from scratch and shows you how to apply C# to develop your next great application.
Getting started
- What is C# – introduces the C# programming language and the .NET
- Install Visual Studio 2022 – guides you on how to install Visual Studio 2022 Community Edition to start programming C#.
- C# Hello World – shows you step by step how to create the first C# program that displays the Hello, World! message on the console window.
- C# syntax – introduces to you the basic C# syntax, including identifiers, keywords, literals, statements, and comments.
Variables & types
- Variables – shows you how to declare variables and use them to hold data in the program.
- integer – introduces the integral types in C# that hold integer numbers.
- float – explains the floating-point number types, including decimal, double, and float.
- char – covers the character type that represents a single character.
- string – discusses the string type and guides you on the basic string operations.
- Raw strings – learns how to use raw strings to make your code more readable.
- bool – learns how to use the bool type to represent boolean values: true and false.
- var – shows you how to use the
var
keyword to declare implicit-typed variables.
Control flow
- if – learns how to check a condition and execute a block if a condition is true.
- if else – shows you how to check multiple conditions and execute a block if a condition is true or another block otherwise.
- if else if – learns how to check multiple conditions and execute a block if a condition is true.
- switch – selects a statement for execution if an expression matches a pattern.
- while – learns how to use the
while
loop statement to conditionally execute a block of code zero or more times. - do while – shows you how to use the
do while
statement to execute a block one or more times based on a condition. - for – guides you on how to execute a block a specified number of times.
- break – show you how to terminate prematurely using the
break
statement. - continue – learns how to start a new loop iteration prematurely using the
continue
statement.
Functions
- Functions – guides you on how to modulize the program and make the code reusable by using functions.
- Default parameters – learns how to simplify the function call using default parameters.
Arrays
- Array – shows you how to use an array to store a fixed number of elements of the same type.
- Multidimensional arrays – learns how to create multidimensional arrays, including 2D and 3D arrays.
- foreach – guides you on how to use the
foreach
statement to iterate over the elements of an array. - Passing an array to a function – shows you how to pass an array to a function as an argument.
- List patterns – shows you how to match an array or a list with a sequence using list patterns.
Classes
- Class – learns about classes and objects, defines a class, and creates objects from the class.
- this keyword – explains the
this
keyword in C#. - public vs. private – guides you on how to use the access modifiers public and private, and how to use them effectively.
- Constructor – shows you how to define constructors to initialize objects.
- Property – learns how to use a property that provides a flexible way to read, write, and compute the value of a private field.
- Constant – introduces constants and how to define them in a method or class.
- Indexer – shows you how to use an indexer to allow an object to be indexed like an array.
- Object initializer – learns how to initialize accessible fields and properties of an object using an object initializer.
- init – specifies an accessor method in a property or indexer that allows assigning a value to the property or indexer element only during object initialization.
Static members & classes
- Static field and property – explains the static fields and properties and how to use them effectively.
- Static method – learns about static methods and how to use them to define a utility class.
- Static constructor – shows you how to define a static constructor that initializes static members.
- Static class – guides you on how to use a static class to define a utility class.
Inheritance
- Inheritance – shows you how to define a class that inherits properties and methods of another class.
- Inheritance & constructor – explains the constructor calling order and shows you how to use the base() syntax to call a specific constructor in the base class.
- new modifier – explains the
new
modifier and how to use it to explicitly hide the member in the base class from the subclass. - virtual modifier – shows you how to use the
virtual
modifier to modify a member of a base class and discuss the differences betweennew
andoverride
methods. - sealed modifier – guides you on the sealed classes and sealed properties and methods.
- Casting – explains how to convert a reference from one type to another using casting, including upcasting and downcasting.
- Abstract classes – introduces you to the abstract classes with practical examples.
- Object – learns about the object that is the base class of all the classes.
- Anonymous types – shows you how to create an anonymous object with a set of read-only properties without defining a class first.
Interfaces
- Interface – introduces interfaces and how to use interfaces to make the application more flexible and extensible.
- Default implementation – shows you how to provide a default implementation for an interface member to make the application backward compatible.
- Explicit Interface Implementation – discusses two ways of implementing interfaces and when to implement interfaces explicitly.
- Extending interfaces – guides you on how to define an interface that extends a single interface or multiple interfaces.
- Abstract classes vs. interfaces – learns how to choose when to use an interface or abstract class.
Exception handling
- try…catch – learns about exceptions and how to use the
try...catch
statement to handle exceptions. - throwing an exception – shows you how to use the
throw
keyword to raise an exception in the application. - try…catch…finally – shows you how to use the
try...catch...finally
statement to handle exceptions and clean up resources. - Rethrow exceptions – learns how to catch an exception and rethrow it using the throw statement.
- Custom exceptions – guides you on how to create and use custom exceptions that provide more information about the exception that occurs.
- Handling global unhandled exception – shows you how to handle the global unhandled exception by subscribing to the
UnhandledException
event.
Generics
- Generics – learns how to use generics to write reusable and type-neutral code.
- Generic Classes – shows you how to define reusable & type-neutral classes.
- Generic Constraints – specifies what types can be used as the type parameters of the generic types.
- Covariance – shows you how to use covariance to define a method that can return a more specific type than what is defined in the method signature.
- Contravariance – guides you on how to use contravariance to define a method that can accept an argument that is less specific than what is defined in the method signature.
Delegates & Events
- Delegates – introduces you to delegates and how to use them to pass methods to other methods as arguments.
- Anonymous Methods – guides you on creating anonymous methods.
- Lambda Expressions – learns how to use lambda expressions to create anonymous functions.
- Events – learns about C# events and how to use the publisher/subscriber pattern to handle events.
- Method group conversion to delegate – explains to you what a method group is and how the method group conversion to delegate process works.
Extension Methods
- Extension methods – learns how to add a method to an existing type without using inheritance.
Working with Date & Time
- DateTime – shows you how to represent multiple values as a single variable.
- DateTime.Parse() – converts a date string to a DateTime object based on a specified culture setting.
- DateTime.ParseExact() – converts a date string to a DateTime object based on an exact format.
- TimeSpan – represents a time interval using the TimeSpan object.
- DateTimeOffset – introduces to you the DateTimeOffset that includes a DateTime and an offset that represents the difference between the local time and UTC.
- DateOnly – learns how to use the DateOnly type to represent the date-only data.
- TimeOnly – shows you how to use the TimeOnly type to represent the time of the day effectively.
Advanced C# Types
- C# value types and reference types – understands the value types and reference types.
- NullReferenceException – deals with NullReferenceException exception that occurs at runtime of the program.
- Nullable Value Type – discusses the nullable value type and how to use it effectively.
- Tuples– shows you how to represent multiple values as a single variable.
- Records – guides you on records that provide built-in functionality for encapsulating data, making it easy to work with immutable and strong-typed data.