extension method

A static method whose first parameter is marked this, so it can be called as though it were an instance method of that type.

In more detail

It adds methods to types you cannot edit. Every AddX and MapX call in ASP.NET Core, such as builder.Services.AddOpenApi(), is an extension method that returns the collection so calls chain.

Example

public static decimal WithVat(this decimal amount, decimal rate) => decimal.Round(amount * (1 + rate), 2);

Related terms

Taught in

References