c#入门遇到小问题一个,大家给我看看啊
刚开始学习c#,照这书上写一个关于类方面的实例,是在vs2005中新建的控制台应用程序项目,代码如下,
using System;
using System.Collections.Generic;
using System.Text;
namespace ConsoleApplication1
{abstract class shape
{ public const double p1=3.14;
protected double x,y
public shape()//构造无参函数
{x=y=0;
}
public shape(double x,double y)
{this.x=x;
this.y=y;
}
public abstract double area }
class rectangle:shape
{public rectangle():base
public rectangle(double x,double y):base(x,y){}
public override void double area()
{return(x*y);}
public double length
{get{return x;}set{if(value> 0){x=value;}}}
public double width
{get{return y;}set{if(value> 0){y=value;}}}
}
class ellipse:shape
{public ellipse(double x,double y):base(x,y){}
public override void double area()
{return pi*x*y;}
}
class circle:ellipse
{public circle (double r):base(r,0){}
public override void double area()
{
return pi*x*x;
}
}
}
class Program
{
static void Main(string[] args)
{
double len = 2.5;
double wid = 3.0;
double rad = 4.1;
rectangle arect=new rectangle();
arect.length=len;
arect.width=wid;
circle acirc=new circle(rad);
Console.WriteLine( "area of rect is:{0} ",arect.area());