I have a base class Sport defined as:
public class Sport
{
public int Id {get; set;}
public string Name {get; set;}
public Sport() {}
public override string ToString()
{
string objectState = string.Format("[Id: {0}; Name: {1};]", Id, Name);
return objectState;
}
}
and I have second class which inherits the Sport class:
public class Basketball : Sport
{
public string PointTerm {get; set;}
public Basketball() {}
//overriding ToString()??
}
How do I override ToString from my base Sport class with an additional property PointTerm?
You can just add a new override in your
Basketballclass:Edit:
You could do something like this if you want to keep in sync with the base class’s implementation, but the simpler approach above is probably better in most circumstances: