Coding With Fun
Home Docker Django Node.js Articles Python pip guide FAQ Policy

What are helper methods and extension methods?


Asked by Emely Burnett on Dec 07, 2021 FAQ



A helper method is just a method that helps you do something else. For example, if you had to find the square root of a number multiple times within a method, you wouldn't write out the code to find the root each time you needed it, you'd separate it out into a method like Math.Sqrt. An extension method is a language feature.
Accordingly,
I use extension methods as much as I can, they are easier to discover if they're put in the proper namespace. Extension methods allow developers to not be aware exactly what the helper class is called and where it is located, not to mention the very fact of its existence.
Consequently, There are two types of Helper methods: 1 Private Class Helper Methods – Located at the bottom of a Class inside of a Helper Region as Static Methods 2 Public Class Helper Methods – Located in Common Assemblies, documented for functionality and location, as Public Static... More ...
In fact,
An extension method is actually a special kind of static method defined in a static class. To define an extension method, first of all, define a static class. For example, we have created an IntExtensions class under the ExtensionMethods namespace in the following example.
Just so,
Extension method. In C# they're implemented as static methods in static classes, with the first argument being of extended class and preceded by " this " keyword. In Smalltalk, any code can add a method to any class at any time, by sending a method creation message (such as methodsFor:) to the class the user wants to extend.