ToString
Open your C# interactive console and pay attention to this.
> class Shoe{}
> Shoe s = new Shoe();
> s.ToString()
"Shoe"
> new System.Random().ToString();
"System.Random"
If we applied ToString method on class name, it will return the name of the class. The interesting idea is we can override ToString() method.
Go to MapLocation class and change the following code.
// before
throw new OutOfBoundsException(x +","+y+" outside the range");
// after
throw new OutOfBoundsException(this +" outside the range");
// result: MakersDefense.MapLocation outside the range
Now, let's override the ToString method on Point class.
public override string ToString()
{
return X + "," + Y;
}