Last active
April 1, 2020 14:55
-
-
Save Ushiosan23/d43db1b228362919ca8c05d6d2113d1a to your computer and use it in GitHub Desktop.
Virtual method example
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| using System; | |
| using System.Collections.Generic; | |
| namespace MyBestNamespace { | |
| public class VirtualMethod { | |
| /// <sumary> | |
| /// Constructor | |
| /// </sumary> | |
| public VirtualMethod() {} | |
| /// <sumary> | |
| /// Virtual method | |
| /// </sumary> | |
| public virtual void SayHello() { | |
| Console.WriteLine("Hello, World!"); | |
| } | |
| } | |
| public class ChildVirtual : VirtualMethod { | |
| /// <sumary> | |
| /// Constructor | |
| /// </sumary> | |
| public ChildVirtual() : base() {} | |
| /// <sumary> | |
| /// Override parent method | |
| /// </sumary> | |
| public override void SayHello() { | |
| // You can use default methot behaviour | |
| base.SayHello(); | |
| // Or use a custom behaviour | |
| Console.WriteLine("This is another sentence"); | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment