DISABLE ADBLOCK

ADBlock is blocking some content on the site

ADBlock errore
Results found: 

Question

Is extension method = static method returning strongly typed variables or collections?

i read one entry about it saying -- "this" keyword as a static method param tells The compiler that this particular Extension Method should be added to objects of type default .net class.

SO do we need to add "this" keyword for creating extended method or every static method in static class can be called extension method?

Solution

From here[^],
"Extension methods are a special kind of static method, but they are called as if they were instance methods on the extended type."

Member 3981366 wrote:
returning strongly typed variables or collections

Sorry, I don't understand what you mean.

Member 3981366 wrote:
do we need to add "this" keyword for creating extended method

Yes, if you want it to be used as an Extension method i.e. the compiler automatically glueing the code for linking the static extension method to the instance object

Member 3981366 wrote:
every static method in static class can be called extension method

No, since you cannnot use static methods with instance object. There lies the major inclination of extension methods.

If you like, leave us your opinion

Was the article helpful and is it translated correctly?

OTHER TIPS

Yes.

When you use static methods within static class and use "this" keyword then this method known as Extended methods.

To specify an extension method you insert the keyword this before the
first method parameter, which indicates to the compiler the type you
want to extend. Note that the method and its class must be static.

Licensed under: CC-BY-SA with attribution
Not affiliated with codeproject.com