ExtensionMethod.NET Home of 880 C#, Visual Basic, F# and Javascript extension methods

What are Extension Methods?

Extension Methods are a language feature that allow you to add methods to an existing type (class, struct, interface, etc). In a language like C#, an Extension Method has at least one parameter (this), which represents the object to operate on. Extension Methods are static methods that are called like class methods. That means that the object it operates on, does not need to be passed to it. Instead it is called on the object itself. Here is a C# example that executes code only if the object it is called on is of a certain type:

public static void IfType<T>(this object item, Action<T> action) where T : class {
    if (item is T) {
        action(item as T);
    }
}

Which then can be called like this:

employee.IfType<Manager>(x => x.ActBusy());

Extension Methods are supported in popular languages like C#, Java, Visual Basic, Ruby, F#, Kotlin and many more. This website has a collection of Extension Methods for C#, Visual Basic, F# and Javascript. All Extension Methods in our database have source code and an example how to use it. We invite people to discuss all submitted code to keep a high standard.

So what are you waiting for? Dig up your favourite Extension Method and add it to the database!

Recently Added Extension Methods