Skip to content

Instantly share code, notes, and snippets.

@Ushiosan23
Last active April 1, 2020 14:55
Show Gist options
  • Select an option

  • Save Ushiosan23/d43db1b228362919ca8c05d6d2113d1a to your computer and use it in GitHub Desktop.

Select an option

Save Ushiosan23/d43db1b228362919ca8c05d6d2113d1a to your computer and use it in GitHub Desktop.
Virtual method example
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