C# Tutorial

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# – introduce the C# programming language and the .NET
  • Install Visual Studio 2022 – guide you on how to install Visual Studio 2022 Community edition to start programming C#.
  • C# Hello World – show you step by step how to create the first C# program that displays the Hello, World! message on the console window.
  • C# syntax – introduce to you the basic C# syntax, including identifiers, keywords, literals, statements, and comments.

Variables & types

  • Variables – show you how to declare variables and use them to hold data in the program.
  • integer – introduce the integral types in C# that hold integer numbers.
  • float – explain to you the floating-point number types, including decimal, double, and float.
  • char – cover the character type that represents a single character.
  • string – discuss the string type and guide you on the basic string operations.
  • bool – learn how to use the bool type to represent boolean values: true and false.
  • var – show you how to use the var keyword to declare implicit-typed variables.

Control flow

  • if – learn how to check a condition and execute a block if a condition is true.
  • if else – show you how to check multiple conditions and execute a block if a condition is true or another block otherwise.
  • if else if – learn how to check multiple conditions and execute a block if a condition is true.
  • switch – select a statement for execution if an expression matches a pattern.
  • while – learn how to use the while loop statement to conditionally execute a block of code zero or more times.
  • do while – show you how to use the do while statement to execute a block one or more times based on a condition.
  • for – guide you on how to execute a block a specified number of times.
  • break – show you how to terminate prematurely using the break statement.
  • continue – learn how to start a new loop iteration prematurely using the continue statement.

Functions

  • Functions – guide you on how to modulize the program and make the code reusable by using functions.
  • Default parameters – learn how to simplify the function call using default parameters.

Arrays

  • Array – show you how to use an array to store a fixed number of elements of the same type.
  • Multidimensional arrays – learn how to create multidimensional arrays, including 2D and 3D arrays.
  • foreach – guide you on how to use the foreach statement to iterate over the elements of an array.
  • Passing an array to a function – show you how to pass an array to a function as an argument.

Classes

  • Class – learn about classes and objects, define a class, and create objects from the class.
  • this – explain the this keyword in C#.
  • public vs. private – guide you on how to use the access modifiers public and private, and how to use them effectively.
  • Constructor – show you how to define constructors to initialize objects.
  • Property – learn how to use a property that provides a flexible way to read, write, and compute the value of a private field.
  • Constant – introduce constants and how to define them in a method or class.
  • Indexer – show you how to use an indexer to allow an object to be indexed like an array.
  • Object initializer – learn how to initialize accessible fields and properties of an object using an object initializer.

Static members & classes

  • Static field and property – explain the static fields and properties and how to use them effectively.
  • Static method – learn about static methods and how to use them to define a utility class.
  • Static constructor – show you how to define a static constructor that initializes static members.
  • Static class – guide you on how to use a static class to define a utility class.

Inheritance

  • Inheritance – show you how to define a class that inherits properties and methods of another class.
  • Inheritance & constructor – explain the constructor calling order and show you how to use the base() syntax to call a specific constructor in the base class.
  • new modifier – explain the new modifier and how to use it to explicitly hide the member in the base class from the subclass.
  • virtual modifier – show you how to use the virtual modifier to modify a member of a base class and discuss the differences between new and override methods.
  • sealed modifier – guide you on the sealed classes and sealed properties and methods.
  • Casting – explain how to convert a reference from one type to another using casting, including upcasting and downcasting.
  • Abstract classes – introduce you to the abstract classes with practical examples.
  • Object – learn about the object that is the base class of all the classes.

Interfaces

  • Interface – introduce interfaces and how to use interfaces to make the application more flexible and extensible.
  • Default implementation – show you how to provide a default implementation for an interface member to make the application backward compatible.
  • Extending interfaces – guide you on how to define an interface that extends a single interface or multiple interfaces.

Exception handling

  • try…catch – learn about exceptions and how to use the try...catch statement to handle exceptions.
  • try…catch…finally – show you how to use the try...catch...finally statement to handle exceptions and clean up resources.

Generics

  • Generics – learn how to use generics to write reusable and type-neutral code.
  • Generic Classes – show you how to define reusable & type-neutral classes.
  • Generic Constraints – specify what types can be used as the type parameters of the generic types.

Delegates & Events

  • Delegates – introduce you to delegates and how to use them to pass methods to other methods as arguments.
  • Anonymous Methods – guide you on creating anonymous methods.
  • Lambda Expressions – learn how to use lambda expressions to create anonymous functions.
  • Events – learn about C# events and how to use the publisher/subscriber pattern to handle events