注册 登录
编程论坛 C# 论坛

错误 1 “ConsoleApplication10.Program.Main(string[])”必须声明主体,因为它未标记为 abstract、extern

yang9988 发布于 2015-06-23 18:03, 2423 次点击
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();
4 回复
#2
yang99882015-06-23 18:03
求大神呀 坐等
#3
Maick2015-06-24 11:28
一个程序只能有一个Main方法
#4
Maick2015-06-24 14:12
static void Main(string[] args);
这句肯定错了..方法直接带;号,,,没有{}
#5
smart07212015-06-28 12:01
嗯,下面的代码应该放在Main方法里面
1