interface IPoint
{
int Px
{
get; set;
}
int Py
{
get; set;
}
}
class ReversePoint : IPoint
{
int x;
int y;
public ReversePoint(int x, int y)
{
this.x = x;
this.y = y;
}
public int Px
{
get { return -x; }
set { x = value; }
}
// Implementing Py similarly to Px
public int Py
{
get { return -y; } // Return the negative of y
set { y = value; } // Set y directly
}
}
class MainClass
{
public static void DisplayPoint( IPoint point)
{
Console.WriteLine(“x={0},y={1}”, point.Px, point.Py);
}
static void Main()
{
ReversePoint p1 = new ReversePoint(-12, -300);
Console.WriteLine(p1.Px);
Console.WriteLine(p1.Py);
ReversePoint p2 = new ReversePoint(12, 300);
//プロパティの参照
DisplayPoint(p2);
}
}