So, I am looking at classes with different behaviours.
And just trying to get back “on the bike” with the various keywords in the Visual C#.NET editor.
Creating a new class and adding a procedure to it….
The master class (HAR HAR) has the function indicated with the virtual keyword. Indicating it could be “taken over” or “highjacked” by a child class that inherits the master class.
This is the master class.
public class MasterVehicle
{
private string _nameOfMasterVehicle = string.Empty;
/// <summary>
/// NameOfVehicle
/// Will set the name of the vehicle. Will only set it if the variable passed in has one or more characters
/// </summary>
/// <param name="TheName"></param>
public virtual void NameOfVehicle(string TheName)
{
if(TheName.Count()>0)
{
// ok there is more than one character in the passed in string
_nameOfMasterVehicle = TheName;
}
}
}
Ok thats the master class…. It has the virtual keyword.
That doesn’t mean that any class that inherits it, needs to take that virtual procedure. OH NO.
But if I want to I can do this:
public class Car : MasterVehicle
{
/// <summary>
/// This is the overriden method that was written in the MasterVehicle class
/// </summary>
/// <param name="TheName"></param>
public override void NameOfVehicle(string TheName)
{
base.NameOfVehicle(TheName);
}
}
There you can see I inherited the master vehicle class in the first declaration of the child class and then put a proc in that uses the override keyword to errrr override the method called “NameOfVehicle”.