Beginning C# 7 Hands-On:Advanced Language Features
上QQ阅读APP看书,第一时间看更新

Adding a virtual function

Now, in the next stage, we will add a virtual function called Perimeter. For this, enter the following beneath the closed curly brace:

public virtual string Perimeter()

Again, we'll centralize as much as we can. So, enter the following within a set of curly braces below this line:

return $"The perimeter of {name} is ";

The specific name can come from this line, because the name instance variable is declared above in private string name. However, the Perimeter will come from the derived classes.

So now, enter the following beneath the preceding closed curly brace:

public class Square : Quad