9

Possible Duplicate:
Extension Method Performance

Will I face performance issues when I´m using extension methods too heavy in any way?

Just an example:

Lets say I´ve 100 extension methods on the type string and a business object that has 50 string properties. Now I create a collection of this business object, maybe 500 items?

Do these extension methods on string have any impact to RAM, CPU, ...?!

I really like extension methods but I´d like to know if there is a limitation concerning its usage.

Community
  • 1
  • 1
timmkrause
  • 3,367
  • 4
  • 32
  • 59

4 Answers4

16

No you will not.

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

Alexey Raga
  • 7,457
  • 1
  • 31
  • 40
5

You might slow intellisense down in the IDE - and possibly make the intellisense lists a bit unwieldy, but it won't have any impact on the execution of the code itself over any other static method.

Rob Levine
  • 40,328
  • 13
  • 85
  • 111
3

An extension method is part of a static class, and it's a syntactic sugar because simulates that some static method is an instance method of some other class.

In conclusion, there's no performance penalty here. It's the same ExtensionMethods.YourExtensionMethod(objectToAddMethod) and objectToAddMethod.YourExtensionMethod().

Matías Fidemraizer
  • 63,804
  • 18
  • 124
  • 206
0

I think this is a duplicate:

See: Is there a performance hit for creating Extension methods that operate off the object type?

The answer there explains this very well!

Community
  • 1
  • 1
Digvijay
  • 361
  • 1
  • 9