From the course: Object-Oriented Programming with C#

Unlock the full course today

Join today to access over 24,900 courses taught by industry experts.

Overriding methods

Overriding methods

- [Instructor] Now it's time for us to create a more unique description for each of the rooms. In order to do this, we're going to look at overriding the ToString method of the Room class. Children classes can override the logic of any parent class. This is one of the key principles of object-oriented coding. While most people think of doing this with custom classes, there are a number of base methods each class inherits in C# that can also be overridden. Let's take a look at how we do this to the logic of the two string method in our room class. Before we do that, we need to add a few things to our Language and English class to start. Let's go ahead and add three properties. The RoomNew property, will be what we show the player when they first enter a room. The RoomOld property, is what we'll show them when they return to the same room they've already visited. Finally, the And property is what we use when we concatenate each of…

Contents