class point
{
int my_x = 1;
public int my_y;
public int x
{
get { return my_x; }//当~~执行程序时,构造函数先被执行。
set
{
if (value < 0)
my_x = value + 100;
else
my_x = value+2;
}
}
public int y
{
get {return my_y; }
set{
if (value < 0)
my_y = value +2;
else
my_y = value;
}
}
public void pppo()
{
System.Console.WriteLine("A:--{0}--{1}",x,y);
}
public point()
{
my_x = 8;
my_y = 0;
}
}
class line
{
private point aaa;
public point start
{
get { return aaa;}
set
{
if (start.x > 0)
start.x = value.x + 1111;
else
start.x = 0;
}
}
public line()
{
aaa = new point();
}
}
class myApp
{
public static void Main()
{
point starting = new point();
starting.pppo();
System.Console.WriteLine("1:--{0}--{1}",starting.x,starting.y);
line App = new line();
App.start.x = 66;
App.start.y = 100;
System.Console.WriteLine("2:---{0}--{1}----", App.start.x, App.start.y);
System.Console.WriteLine("3:--{0}--{1}", starting.x,starting.y);
starting.pppo();
System.Console.WriteLine("4:=={0}=={1}==", starting.x, starting.my_y);
starting.x = 5;
starting.my_y = 9;//因为my_y被声明为公有~所以能够直接赋值。
System.Console.WriteLine("5:=={0}=={1}==", starting.x, starting.my_y);
System.Console.ReadLine();
}
}
结果:
A:--8--0
1:--8--0
2:---68--100---
3:--8--0
A:--8--0
4:==8==0
5:==7==9
--------------------------------------------------------------
刚刚学习C#,问题可能有些愚蠢~~不要见怪.
App.start.x = 66;
App.start.y = 100;
为什么这里的值写到~~point类的x 和y呢?
------------------------------------------------
public point start
{
get { return aaa;}
set
{
if (start.x > 0)
start.x = value.x + 1111;
else
start.x = 0;
}
}
这里的set语句~不会改变~App.start.x的值呢?象是多余的.