C# › Extension Methods

How does method resolution priority work when an extension method has the SAME name and signature as an actual instance method on the type?

Intermediate

Answer

A genuine INSTANCE method on the type ALWAYS takes priority over an extension method with a matching signature — the compiler only falls back to searching for an applicable extension method if no instance method (or property/field) matches, meaning you can never accidentally 'override' real instance method behavior with an extension method.
public class Calculator {
  public int Add(int a, int b) => a + b; // real instance method
}
public static class CalculatorExtensions {
  public static int Add(this Calculator calc, int a, int b) => 999; // never actually called
}
new Calculator().Add(2, 3); // always calls the instance method, returns 5
Real-world example Understanding why adding an extension method with the same name as an existing instance method silently has no effect on calls to that instance method.

Common follow-ups: What happens if TWO different extension methods (from different namespaces) both match the same call?