Short guide to C#

A quick guide and examples collected from various sources

List patterns C#

You can check elements in a list or an array using a list pattern. Consider the following excerpt from a text file containing bank transactions: 04-01-2020, DEPOSIT,    Initial d…

Indices and ranges C#

Indices and ranges provide a succinct syntax for accessing single elements or ranges in a sequence. Indexes and ranges provide clear, concise syntax to access a single element or a range of elements in a sequence. An index expression typically returns the type of the elements of a sequence.

Create and throw exceptions C#

Things to avoid when throwing exceptions Don't use exceptions to change the flow of a program as part of ordinary execution. Use exceptions to report and handle error conditions. Exceptio…

Pattern Multiple inputs C#

You can write patterns that examine multiple properties of an object. public record Order(int Items, decimal Cost);   The following code examines the number of items and the value of an…

Project File .csproj

Each C# project has a file that is responsible for the overall configuration of the project. By default, this file is called NameProject.csproj. <Project Sdk="Microsoft.NET.Sdk"> …

Classes and structures of C#

Each type in the CTS is defined as either a value type or a reference type. These types include all custom types in the .NET class library and also your own user-defined types. Types t…

Anonymous types C#

In situations where it isn't convenient or necessary to create a named class you use anonymous types. Anonymous types are defined by their named data members.

Polymorphism C#

Polymorphism is a Greek word that means "many-shaped". When this polymorphism occurs, the object's declared type is no longer identical to its run-time type.