I'm a beginner to c# programming and recently started working on a bachelors degree. What I'm trying to say is, I'm new.
I have marked the place where I have the problem. The problem is that I don't understand why I need to put override in the code at all.
There is 2 var of the type object (first and rest).
public Pair()
{
first = rest = null;
}
public Pair(Object o)
{
first = o;
rest = null;
}
public Object First()
{
return(first);
}
public Object Rest()
{
return(rest);
}
public Pair Connect(Object o)
{
rest = o;
return(this);
}
//Here is the "override string ToString" I don't understand. Why do I need to override this?
public override string ToString()
{
string output = "(";
Pair p = this;
while (p != null) {
if (p.First() == null)
output += "NULL";
else
output += p.First().ToString();
if (p.Rest() is Pair)
p = (Pair)(p.Rest());
else {
if (p.Rest() != null)
output += " . " + rest.ToString();
break;
}
output += " ";
}
output += ")";
return(output);
}