Extension methods: performance issue with too much use?

Possible duplicate:
Extension Method Performance

Will I encounter performance issues when I use extension methods too much?

Just an example:

Suppose I have 100 extension methods for a type string and a business object that has 50 string properties. Now I am creating a collection of this business object, perhaps 500 items?

Do these extension methods in the line help affect RAM, CPU, ...?!

I really like extension methods, but I would like to know if there is a restriction regarding its use.

+7
source share
4 answers

No, you won’t.

Extension methods are just regular static methods with some syntactic sugar. Use them as much as you want :)

+13
source

You can slow down intellisense in the IDE - and perhaps make intellisense lists a little cumbersome, but that will not have any effect on the execution of the code itself on any other static method.

+5
source

The extension method is part of the static class and is syntactic sugar, because it imitates that some static method is an instance method of another class.

In conclusion, there is no penalty for performance. These are the same ExtensionMethods.YourExtensionMethod(objectToAddMethod) and objectToAddMethod.YourExtensionMethod() .

+3
source

I think this is a duplicate:

See: Does success arise when creating extension methods that work with an object type?

The answer there explains it very well!

+1
source

All Articles