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 8722423
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T07:24:57+00:00 2026-06-13T07:24:57+00:00

public class StoreController : Controller { public string Index() { // implicitly specified instance

  • 0
public class StoreController : Controller
{
    public string Index()
    {
        // implicitly specified instance does not work
        //return GetMemberName();

        // must specify this explicitly
        return this.GetMemberName();
    }
}

public static class Utilities
{
    public static string GetMemberName(this Controller caller,
        [CallerMemberName] string memberName = "")
    {
        return caller.GetType().FullName + "." + memberName;
    }
}

Why do we have to explicitly specify this when invoking an extension method from within a method of a class being extended?

In my mental model, we usually can omit this such as when we initialize fields, for example.

  • 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-06-13T07:24:59+00:00Added an answer on June 13, 2026 at 7:24 am

    Without being present at the design board meeting where this was decided it’s hard to say why it’s like that.

    In this text I use method or instance method in the sense of a function associated with a specific object instance and I use function in a mathematical sense. A function receives a number of arguments and creates a result (which is potentially void)

    If we do not consider virtual methods which are more complex because the actual function to be called is determined runtime then any and all method calls are syntactic sugar. If we have two methods defined below

    internal static class Extensions {
      public static string FooEx(this MyClass self){
         return self.ToString();
      }
    }
    
    internal class MyClass {
      public string Bar(){
         var s1 = Foo();
         var s2 = this.FooEx();
      }
    
      private string Foo(){
          return ToString();
      }
    }
    

    Then both will be translated to a function call where the first (and only) argument in both cases will be the object identified by this. If you are doubtful about this then look at the IL produced for any call to an instance method and you will notice there’s an extra argument compared to the declaration in code. This argument is the thisreference, which is always passed as the first argument to an instance method.

    So in the case of an instance method the compiler still need to determine which object to pass as the first argument to the function. That is exactly the same it has to do if you are calling an extension method without this which also means that can’t be the real reason why you have to use this in front of an extension method.

    In the compiler for Marvin, a compiler build on top of the Mono compiler I had to do a similar trick as C# does with extension methods and wondered why the specs require the this
    The real reason why the compiler enforces you to use this before an extension method is that the specs says so. What the reason behind that decision is would need the attention of some one like @EricLippert who where probably there when they decided on that requirement

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

Sidebar

Related Questions

public class MyClass { public string MyProperty{ get; set; } Now, I would like
public class Test { public static void main(String[] args) { DemoAbstractClass abstractClass = new
public class A { private A(int param1, String param2) {} public static A createFromCursor(Cursor
public class Base{ protected String str; public static final Base ERROR = new Base(error);
public class saveButtonListener implements ActionListener{ public void actionPerformed(ActionEvent ev){ JFileChooser chooser= new JFileChooser(); String
public class IdAsync extends AsyncTask<String, Void, Void> { AlertDialog alertDialog = new AlertDialog.Builder(MainClass.this).create(); protected
public class Employee { public static void main(String[] args) { int j=3; staples[] stemp
public class MyEncrypt { public void saveToFile(String fileName, BigInteger mod, BigInteger exp) throws IOException
public class InterruptedInput { public static void main(String[] args) { InputThread th=new InputThread(); //worker
public class BobDatabase extends SQLiteOpenHelper{ private static final String DATABASE_NAME = bob.db; private static

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.