Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6099703
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T13:18:11+00:00 2026-05-23T13:18:11+00:00

How are extension methods implemented internally? I mean what happens when the compiler sees

  • 0

How are extension methods implemented internally? I mean what happens when the compiler sees a declaration for an extension method and what happens at runtime when there is a call to an extension method.

Is reflection involved? Or when you have an extension method is its code injected in the target class type metadata with some additional flags noting that this is an extension method and then the CLR knows how to handle that?

So in general, what happens under the hood?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T13:18:11+00:00Added an answer on May 23, 2026 at 1:18 pm

    As already have said by other colleagues it is just a static method.
    It is all about the compiler we can say that CLR even have no idea about extension methods.
    You can try to check IL code ..

    Here is an example

    static class ExtendedString
    {
        public static String TestMethod(this String str, String someParam)
        {
            return someParam;
        }
    }
    
    static void Main(string[] args)
    {
        String str = String.Empty;
        Console.WriteLine(str.TestMethod("Hello World!!"));
        ........
    }
    

    And here is the IL code.

      IL_0001:  ldsfld     string [mscorlib]System.String::Empty
      IL_0006:  stloc.0
      IL_0007:  ldloc.0
      IL_0008:  ldstr      "Hello World!!"
      IL_000d:  call       string StringPooling.ExtendedString::TestMethod(string,
                                                                           string)
      IL_0012:  call       void [mscorlib]System.Console::WriteLine(string)
      IL_0017:  nop
    

    As you can see it is just a call of static method.
    The method is not added to the class, but compiler makes it look like that.
    And on reflection layer the only difference you can see is that CompilerServices.ExtensionAttribute is added.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've implemented some extension methods as defined here . I've put these into a
C# 3.0 Extension methods add extensions to the base Type making calling that method
I've implemented some extension methods and put those in separate Class Library project. Imagine
Is there a way to override extension methods (provide a better implementation), without explicitly
Using extension method we can create methods to convert an enum to other datatype
From my mentor: Prefer native methods (implemented directly on the collection) over extension methods
Honestly I hate extension methods as disscussed before. I have a extension method as
At a previous organization, we implemented an extension method that created a shorthand for
We wrote a small Windows class library that implements extension methods for some standard
Since String implements IEnumerable<char> , I was expecting to see the Enumerable extension methods

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.