Skip to content

Instantly share code, notes, and snippets.

@hagbarddenstore
Created August 12, 2013 14:49
Show Gist options
  • Save hagbarddenstore/6211476 to your computer and use it in GitHub Desktop.
Save hagbarddenstore/6211476 to your computer and use it in GitHub Desktop.
void Main()
{
var animals = new Animal[] { new Cat(), new Dog() };
MakeSound makeSound;
foreach (var animal in animals)
{
makeSound = animal.MakeSound;
makeSound();
}
}
abstract class Animal
{
public abstract void MakeSound();
}
class Cat : Animal
{
public override void MakeSound()
{
Console.WriteLine("Mjau!");
}
}
class Dog : Animal
{
public override void MakeSound()
{
Console.WriteLine("Woof!");
}
}
delegate void MakeSound();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment