Extension Methods

The method that allows to add methods to existing type without creating a new derived type, recompiling, or otherwise modifying the original type.

A method signature template with a return value and an argument

public static <T_RETURN> <METHOD_NAME>(this <T_TYPE> <VAR_NAME>, <T_ARG1_TYPE> <ARG1_NAME>)
Token Description
T_RETURN The type of the return value.
METHOD_NAME The desired name of the method.
T_TYPE The existing type to extend.
VAR_NAME The holder of an instance of the T_TYPE
T_ARG1_TYPE Type of the first argument.
ARG1_NAME The name of the first argument.

This method is actually a static method but the first argument has the keyword this and the target type to extend. Also it holds the instance of the target type.

The T_RETURN and the argument part of the template are optional. Also the argument is not limited to just one, you can have as many as required by your extension.