错误 1 “ConsoleApplication10.Program.Main(string[])”必须声明主体,因为它未标记为 abstract、extern
static void Main(string[] args);struct APoint//描述点数据的结构
{
public int X;//x坐标
public int Y;//y坐标
public APoint(int point_X, int point_Y)//带参数的构造函数
{
this.X = point_X;
this.Y = point_Y;
}
public void Move(int offset_X, int offset_Y)//移动点坐标的办法
{
X += offset_X;
Y += offset_Y;
}
public override string ToString()//重载tostring方法
{
return X.ToString() + "," + Y.ToString();
Console.WriteLine("使用ArrayList");
ArrayList pnts = new ArrayList(3);
for (int i = 0; i < 3; i++)
{
pnts.Add(new APoint(100, 100));//ArrayList赋值
}
for (int i = 0; i < 3; i++)
{//ArrayList中的元素执行Move方法 伴随着装箱和取消装箱,原数组元素的值并未改变
((APoint)pnts[i]).Move(400, 400);
}
for (int i = 0; i < 3; i++)
{ Console.WriteLine("第" + i.ToString() + "点的坐标是(" + pnts[i].ToString() + ")"); }
Console.WriteLine("使用数组");
APoint[] points = new APoint[3];
for (int i = 0; i < 3; i++)
{ points[i] = new APoint(100, 100); }//数组赋值
Console.WriteLine("使用foreach循环");
foreach (APoint point in points)
{//数组中的元素执行Move方法,在foreach循环中伴随装箱过程,原数组元素并未改变
point.Move(400, 400);
}
for (int i = 0; i < 3; i++)
{ Console.WriteLine("第" + i.ToString() + "点的坐标是(" + points[i].ToString() + ")"); }
Console.WriteLine("使用for循环");
for (int i = 0; i < 3; i++)
{//直接操作数组中的元素,没有装箱和取箱的过程,原数组的元素发生改变
points[i].Move(400, 400);
}
for (int i = 0; i < 3; i++)
{
Console.WriteLine("第" + i.ToString() + "点的坐标是(" + points[i].ToString() + ")");
}
Console.ReadLine();