C#初学编程问题
求思路啊,帮帮忙哦[ 本帖最后由 宇智波曌 于 2011-10-19 10:43 编辑 ]
public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void Form1_Load(object sender, EventArgs e) { Square s = new Square(); s.Length = 2; Pentagon p = new Pentagon(); p.Length = 5; MessageBox.Show(s.GetPeri() + "\n" + p.GetPeri()); } } public class Polygen { private int length = 0; private int sides = 0; public int Length { get { return length; } set { length = value; } } public int Sides { get { return sides; } set { sides = value; } } public Polygen() { Length = 1; } public virtual string GetPeri() { return "This is a virtual method."; } } public class Square : Polygen { public Square() { Sides = 4; } public override string GetPeri() { return "The perimeter of the Polygon is " + Sides * Length; } } public class Pentagon : Polygen { public Pentagon() { Sides = 5; } public override string GetPeri() { return "The perimeter of the Polygon is " + Sides * Length; } }