Skip to content

Instantly share code, notes, and snippets.

@tuannguyenssu

tuannguyenssu/LSP1Before.cs Secret

Created Jul 7, 2019
Embed
What would you like to do?
public class Bird
{
public virtual void Fly()
{ Console.Write("Fly");
}
}
public class Eagle : Bird
{
public override void Fly()
{ Console.Write("Eagle Fly");
}
}
public class Duck : Bird
{
public override void Fly()
{ Console.Write("Duck Fly");
}
}
public class Penguin : Bird
{
public override void Fly()
{ throw new NoFlyException();
}
}
var birds = new List { new Bird(), new Eagle(), new Duck(), new Penguin() };
foreach(var bird in birds) bird.Fly();
// Tới pengiun thì lỗi vì cánh cụt quăng Exception
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment