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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T16:37:48+00:00 2026-05-26T16:37:48+00:00

Given interface public interface IHaveError { string ErrorMessage { get; set; } } Extension

  • 0

Given interface

public interface IHaveError
{
    string ErrorMessage { get; set; }
}

Extension

public static class HaveErrorExtensions
{
    public static void SetErrorMessage(this IHaveError target, string message)
    {
        target.ErrorMessage = message;
    }
}

Class

public class HaveError : IHaveError
{
    public string ErrorMessage { get; set; }

    public void DoSomething()
    {
        this.SetErrorMessage(message);
    }
}

Why is this. required on the call to the extension method? The name is not resolved without it.

  • 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-26T16:37:49+00:00Added an answer on May 26, 2026 at 4:37 pm

    This is how extension methods work in the C# language spec. If you read section “7.6.5.2 Extension method invocations”, it basically says that you must have a method invocation of one of the following forms:

    expr . identifier ( )
    expr . identifier ( args )
    expr . identifier < typeargs > ( )
    expr . identifier < typeargs > ( args )
    

    If you note, expr is required for an extension method search to be an option.

    In this case, this. becomes the expr. above, so that the above can get translated into the static method invocation for a type where it’s an extension method defined as:

    C . indentifier ( expr , args )
    

    In your case, in order for the compiler to “find” (or even search for) the method call, you need to have some “expr” type specified. The explicit this. qualifies. It causes the compiler to take this:

    this.SetErrorMessage(message);
    

    And search for a matching extension method that works with the type, translating it into:

    HaveErrorExtensions.SetErrorMessage(this, message);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Given this: Interface IBase {string X {get;set;}} Interface ISuper {string Y {get;set;}} class Base
Given the interface below: public interface ITest { string PropTest1 { get; set; }
Given this code public interface IRepository<T> { IQueryable<T> GetAll(); } and this public class
Given this interface public interface IMyInterface { string Method1(); } Why is this valid
Given an example such as .. public interface IInterface { } public static void
Given 2 interfaces having one function in common public interface I1 { void Foo(string
Given this magical interface: public interface IHat<out TRabbit> { TRabbit Take(); } And this
Given a base class with the following interface: public class Base { public virtual
Given a basic repository interface: public interface IPersonRepository { void AddPerson(Person person); List<Person> GetAllPeople();
Given the following code: public interface IExample { ... } public abstract class BaseExample:

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.