The derived class contains the Count method, which performs some actions on the Derived class. On the other hand, I have an extension method that also targets the Derived class.
Derived derived = new Derived(); derived.Count();
Calling the fragment above, the "Count" method will be executed inside the derived class. Why the C # compiler does not warn or identify the extension method in this situation. How does the infrastructure internally handle this?
//Base class public class Base { public virtual string Count() { return string.Empty; } } //Derived class public class Derived : Base { public override string Count() { return base.Count(); } } //Extension Methods for Derived class public static class ExtensionMethods { public static Derived Count(this Derived value) { return new Derived(); } }
source share