In your line Console.WriteLine(rectangle.Perimeter());
you are calling Console.WriteLine on a method that returns nothing. In fact that Perimeter() is doing a Console.WriteLine itself!
The best fix would be to return a value from that method:
abstract class Figure
{
public abstract int Perimeter();
}
and of course fix the actual implementations by replacing the Console.WriteLine with a return
.
If you really really want that method to do its own printing, then just call the method: rectangle.Perimeter();
No extra Console.WriteLine needed, as that method already takes care of it (and there is nothing to print anyway).
As to why the compiler's error message (CS1503) mentions "bool": Console.WriteLine has multiple overloads and none of them fit. The compiler chooses one (apparently with a bool
argument) and complains that your argument (type void) doesn't fit.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…