欢迎大家来到IT世界,在知识的湖畔探索吧!
要在属于同一种类的对象之间共享数据值,可以使用static。
namespace demo3
{
class point //定义点
{
public int x;
public int y;
}
class line
{
static public point origin = new point();
public point ending = new point();
}
class Program
{
static void Main(string[] args)
{
line lin1 = new line();
line lin2 = new line();
line.origin.x = 1;
line.origin.y = 5;
lin1.ending.x = 6;
lin1.ending.y = 7;
lin2.ending.x = 8;
lin2.ending.y = 9;
Console.WriteLine("1开始点 {0}{1}",line.origin.x,line.origin.y);
Console.WriteLine("1结束点 {0} {1}",lin1.ending.x,lin1.ending.y);
Console.WriteLine("2开始点 {0}{1}", line.origin.x, line.origin.y);
Console.WriteLine("2结束点 {0} {1}", lin2.ending.x, lin2.ending.y);
line.origin.x = 999;
line.origin.y = 888;
Console.WriteLine("1开始点 {0}{1}", line.origin.x, line.origin.y);
Console.WriteLine("1结束点 {0} {1}", lin1.ending.x, lin1.ending.y);
Console.WriteLine("2开始点 {0}{1}", line.origin.x, line.origin.y);
Console.WriteLine("2结束点 {0} {1}", lin2.ending.x, lin2.ending.y);
Console.ReadKey();
}
}
}
欢迎大家来到IT世界,在知识的湖畔探索吧!
免责声明:本站所有文章内容,图片,视频等均是来源于用户投稿和互联网及文摘转载整编而成,不代表本站观点,不承担相关法律责任。其著作权各归其原作者或其出版社所有。如发现本站有涉嫌抄袭侵权/违法违规的内容,侵犯到您的权益,请在线联系站长,一经查实,本站将立刻删除。 本文来自网络,若有侵权,请联系删除,如若转载,请注明出处:https://itzsg.com/30419.html