Created
August 12, 2013 14:49
-
-
Save hagbarddenstore/6211476 to your computer and use it in GitHub Desktop.
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
| 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