public abstract class A
{
// Class members here.
}
public abstract class A
{
public abstract void DoWork(int i);
}
// compile with: /target:library
public class D
{
public virtual void DoWork(int i)
{
// Original implementation.
}
}
public abstract class E : D
{
public abstract override void DoWork(int i);
}
public class F : E
{
public override void DoWork(int i)
{
// New implementation.
}
}
csc abstractshape.cs shapes.cs shapetest.cs
// compile with: csc /target:library abstractshape.cs
public abstract class Shape
{
private string name;
public Shape(string s)
{
// calling the set accessor of the Id property.
Id = s;
}
public string Id
{
get
{
return name;
}
set
{
name = value;
}
}
// Area is a read-only property - only a get accessor is needed:
public abstract double Area
{
get;
}
public override string ToString()
{
return Id + " Area = " + string.Format("{0:F2}", Area);
}
}
public abstract double Area
// compile with: csc /target:library /reference:abstractshape.dll shapes.cs
public class Square : Shape
{
private int side;
public Square(int side, string id)
: base(id)
{
this.side = side;
}
public override double Area
{
get
{
// Given the side, return the area of a square:
return side * side;
}
}
}
public class Circle : Shape
{
private int radius;
public Circle(int radius, string id)
: base(id)
{
this.radius = radius;
}
public override double Area
{
get
{
// Given the radius, return the area of a circle:
return radius * radius * System.Math.PI;
}
}
}
public class Rectangle : Shape
{
private int width;
private int height;
public Rectangle(int width, int height, string id)
: base(id)
{
this.width = width;
this.height = height;
}
public override double Area
{
get
{
// Given the width and height, return the area of a rectangle:
return width * height;
}
}
}
// compile with: csc /reference:abstractshape.dll;shapes.dll shapetest.cs
class TestClass
{
static void Main()
{
Shape[] shapes =
{
new Square(5, "Square #1"),
new Circle(3, "Circle #1"),
new Rectangle( 4, 5, "Rectangle #1")
};
System.Console.WriteLine("Shapes Collection");
foreach (Shape s in shapes)
{
System.Console.WriteLine(s);
}
}
}
Shapes Collection Square #1 Area = 25.00 Circle #1 Area = 28.27 Rectangle #1 Area = 20.00
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有