using System;
namespace class_this
{
class Class1
{
public class CPoint
{
public int a = 11;
public int x, y;
static int z = 22;
public CPoint() {}
public CPoint(int x, int y)
{
this.x = x;
this.y = y;
}
public void show()
{
Console.WriteLine("show() a = {0} x = {1} y = {2} z = {3}", a, x, y, z++);
}
public void this_show()
{
Console.WriteLine("this_show() a = {0} x = {1} y = {2} z = {3}", this.a, this.x,
this.y, z++);
// this.z = Error (z cannot be accessed with an instance reference - this)
}
}
static void Main(string[] args)
{
CPoint p1 = new CPoint();
CPoint p2 = new CPoint();
CPoint p3 = new CPoint(60, 80);
p1.show(); // show() a = 11 x = 0 y = 0 z = 22
p2.show(); // show() a = 11 x = 0 y = 0 z = 23
p3.show(); // show() a = 11 x = 60 y = 80 z = 24
Console.WriteLine("\n");
p1.this_show(); // this_show() a = 11 x = 0 y = 0 z = 25
p2.this_show(); // this_show() a = 11 x = 0 y = 0 z = 26
p3.this_show(); // this_show() a = 11 x = 60 y = 80 z = 27
}
}
}