Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- The override modifier may be used on virtual methods and must be used on abstract methods. This indicates for the compiler to use the last defined implementation of a method. Even if the method is called on a reference to the base class it will use the implementation overriding it.
- public class A
- {
- public virtual void One();
- public void Two();
- }
- public class B : A
- {
- public override void One();
- public new void Two();
- }
- B b = new B();
- A a = b as A;
- a.One(); // Calls implementation in B
- a.Two(); // Calls implementation in A
- b.One(); // Calls implementation in B
- b.Two(); // Calls implementation in B
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement