This is a fundamental topic in C# and if you plan to do any development at all with the language you need to know this. Override is used for changing the behavior of the original type’s method or property. The new keyword, in this case, is used for scratching the existing behavior but only in the current type. To better explain this, consider the following code.
1 2 3 4 5 6 7 8 9 10 11 | public class Foo{ public virtual void Print(){ Console.WriteLine("I am a Foo!"); } } public class Bar : Foo{ public override void Print(){ Console.WriteLine("I am a Bar!"); } } |
If we declare a Bar and cast it to a Foo in the above code, we will still get “I am a Bar!” when we invoke the Print method. However, if we change the code to the following things will get messed up a bit.
1 2 3 4 5 6 7 8 9 10 11 | public class Foo{ public void Print(){ Console.WriteLine("I am a Foo!"); } } public class Bar : Foo{ public new void Print(){ Console.WriteLine("I am a Bar!"); } } |
If we instantiate a Bar, we will get the new functionality. However, if we cast that Bar object into a Foo, we will get the implementation provided by the Foo. So be sure of what you are using and why!
Oh Fallout 3, how I love thee. The game is fantastic. A must buy for anyone interested in shooting people, leveling up, causing massive destruction or any combination of the above. But oh how the main story is just one let down after another. I have mistaken this game for a game made by Bethesda; a game where your actions directly influence the story at pinnacle moments. Instead this is a game where you are built up to a high and then let down when the story takes a sudden left turn and you have no choice but to follow it. And these sudden left turns, oh how predictable they are, are so basic that it just makes you bleed with agony over what could have been.
But in the end, I am going back to start a new character and do it all over again. That is how good this game is.