Search code examples
c#virtual

Virtual method refers dynamic or static type?


As a brand new in .NET, just to clarify to myself:

virtual method refers to the dynamic or static object type?

Base myObject = new Derived();
myObject.Foo(); 

Foo() of derived class is invoked (assume that Foo() is virtual in Base and overridden in Derived)?


Solution

  • You are correct.

    The terms "static" and "dynamic" type are wrong here. Everything here is statically typed.