第一次写Blog
2007-05-08 17:31
281 查看
using System;
namespace Polymorphic
{
interface IPoint
{
int X{get;set;}
int Y{get;set;}
double area();
}
class MyPoint : IPoint
{
private int x;
private int y;
public MyPoint(int x, int y)
{
this.x = x;
this.y = y;
}
public int X
{
get{return x;}
set { x = value; }
}
public int Y
{
get { return y; }
set { y = value; }
}
public double area()
{
return x * y;
}
}
class Program
{
private static void printPoint(IPoint ip)
{
Console.WriteLine("x={0},y={1}", ip.X, ip.Y);
}
static void Main(string[] args)
{
MyPoint myPoint = new MyPoint(2, 3);
Console.Write("My Point: ");
printPoint(myPoint);
Console.WriteLine(myPoint.area().ToString());
}
}
}
namespace Polymorphic
{
interface IPoint
{
int X{get;set;}
int Y{get;set;}
double area();
}
class MyPoint : IPoint
{
private int x;
private int y;
public MyPoint(int x, int y)
{
this.x = x;
this.y = y;
}
public int X
{
get{return x;}
set { x = value; }
}
public int Y
{
get { return y; }
set { y = value; }
}
public double area()
{
return x * y;
}
}
class Program
{
private static void printPoint(IPoint ip)
{
Console.WriteLine("x={0},y={1}", ip.X, ip.Y);
}
static void Main(string[] args)
{
MyPoint myPoint = new MyPoint(2, 3);
Console.Write("My Point: ");
printPoint(myPoint);
Console.WriteLine(myPoint.area().ToString());
}
}
}