class Point
{
private int x;
public int X
{
get
{
return x;
}
set
{
x = value;
}
}
private int y;
public int Y
{
get
{
return y;
}
set
{
y = value;
}
}
public Point(int x = 10, int y = 20)
{
this.x = x;
this.y = y;
}
}
测试2
class Rectangle
{
private double l;
public double L
{
get
{
return l;
}
set
{
l = value;
}
}
private double w;
public double W
{
get
{
return double.Parse(w.ToString("0.0"));
//return w;
}
set
{
w = value;
}
}
public double GetArea()
{
//double Area = this.l * this.w;
//string s1 = string.Format("{0:F1}", Area);
//return s1;
return l * w;
}
public string GetPerimeter()
{
double Perimeter = 2*(this.l + this.w);
string s2 = string.Format("{0:F1}", Perimeter);
return s2;
//return Perimeter;
}
public Rectangle(double l, double w)
{
this.l = l;
this.w = w;
}
}
测试3:
class TxtReader
{
private string path;
public string Path
{
get { return path; }
set { path = value; }
}
public TxtReader(string path)
{
this.path = path ;
}
public string ReadContent()
{
string Content = System.IO.File.ReadAllText(path );
return Content;
}
}
测试4:
class TxtWriter
{
private string path;
public string Path
{
get { return path; }
set { path = value; }
}
public TxtWriter(string path)
{
this.path = path;
}
public void WriteContent(string s)
{
string str1 = s;
System.IO.File.WriteAllText(path , str1);
}
}
测试5:
abstract class Polygon
{
public abstract int GetArea();
}
class RectangleClass : Polygon
{
private int length;
public int Length
{
get { return length; }
set { length = value; }
}
private int width;
public int Width
{
get { return width; }
set { width = value; }
}
public override int GetArea()
{
return this.Length * this.Width; ;
}
public RectangleClass(int length, int width)
{
this.Length = length;
this.Width = width;
}
}
class SquareClass : Polygon
{
private int side;
public int Side
{
get { return side; }
set { side = value; }
}
public override int GetArea()
{
return this.Side * this.Side;
}
public SquareClass(int side)
{
this.Side = side;
}
}