Just out of curiosity: are calls using the base
keyword in C# dynamically bound (i.e. is it a polymorphic call)?
Consider the following example:
public class A
{
public virtual void WriteSomething()
{
Console.WriteLine("Hello from A");
}
}
public class B : A
{
public override void WriteSomething()
{
base.WriteSomething();
Console.WriteLine("Hello from B");
}
}
public class Program
{
public static void Main()
{
A instance = new B();
instance.WriteSomething();
}
}
I know that when a client (in this example the Main
method) calls instance.WriteSomething
, this call is dynamically bound. But what about the base.WriteSomething
call in the overridden method in class B
? I assume that it is not dynamically bound because the compiler knows the base class at compile time and therefore Dynamic Binding is not necessary - but I couldn't find any documentation on that.
Thanks for your help in advance!