Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Performance Extension Method vs. Instance Method

Tags:

c#

asp.net

Is there any performance difference between an instance method and an extension method?

like image 495
Alex Avatar asked Jul 28 '09 17:07

Alex


2 Answers

Don't forget extension methods are just static method calls wrapped in syntactic sugar. So what you're really asking is

Is there a performance difference between static and instance methods

The answer is yes and there are various articles available on this subject

Some links

  • http://msdn.microsoft.com/en-us/magazine/cc507639.aspx
  • http://msdn.microsoft.com/en-us/magazine/cc500596.aspx
like image 57
JaredPar Avatar answered Oct 22 '22 06:10

JaredPar


I would doubt there would be any performance difference because it is all syntactic sugar. The compiler just compiles it just as any other method call, except it is to a static method on a different class.

Some more details from my blog about the syntactic sugar: http://colinmackay.co.uk/2007/06/18/method-extensions/

like image 21
Colin Mackay Avatar answered Oct 22 '22 06:10

Colin Mackay