Virtual and Overridden Methods in C# (Complete Course in Adventure Game Programming)

Опубликовано: 10 Февраль 2025
на канале: Code With Huw
502
19

Often we will want to handle mixed lusts of objects – for example, a Room may contain a list containing Treasure, MagicTreasure and Weapon objects – that is, objects derived from three different classes. Each object has a different Describe() method. So how can we be sure that the correct version of the method is called when we iterate over a list (in which we can’t know in advance which type of object each list element actually is)?

The answer is virtual methods which are overridden?
WHAT???
This may sound complicated but it isn’t really. As I explain in this lesson.

To follow this course, bookmark the Complete Course In Adventure Game Programming Playlist:
   • Complete Course in Adventure Game Pro...  

Huw Collingbourne is author of The Little Book Of Adventure Game Programming In C#. Available from:
Amazon (US) https://amzn.to/33M6sQ4
Amazon (UK) https://amzn.to/2YtaBrj

And also, The Little Java Book Of Adventure Game Programming. Available from:
Amazon (US) https://amzn.to/3gizI93
Amazon (UK) https://amzn.to/3mydF0e

If you are eager to get working on your own adventure game, you can download Huw’s free game-writing code libraries, BIFF (the Bitwise Interactive Fiction Framework) from:
http://www.bitwisebooks.com

Facebook:   / codewithhuw