为什么编好运行控制台应用程序时,出现错误,说是无法创建新的堆栈防护页面

Imant_ 2012-02-29 12:42:30
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication6
{
public abstract class Animal
{
public int x;
public int y;
public int X
{
get
{
return x;
}
set
{
X = ((value >= 1) && (value <= 168)) ? value : 0;
}
}
public int Y
{
get
{
return y;
}
set
{
Y = ((value >= 1) && (value <= 168)) ? value : 0;
}
}
public Animal(int m, int n)
{
X = m;
Y = n;
}
public abstract void Move();

}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication6
{
class Fish:Animal
{
public Fish(int m, int n)
:base (m,n)
{
X += 10;
Y += 10;
}
public override void Move()
{
Console.WriteLine("Fish:\nX={0}\nY={1}",X,Y);
}
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication6
{
class Frog:Animal
{
public Frog(int m, int n)
:base (m,n)
{
X += 20;
Y += 20;
}
public override void Move()
{
Console.WriteLine("Frog:\nX={0}\nY={1}",X,Y);
}
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication6
{
class Bird:Animal
{
public Bird(int m, int n)
:base (m,n)
{
X += 30;
Y += 30;
}
public override void Move()
{
Console.WriteLine("Fish:\nX={0}\nY={1}",X,Y);
}
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication6
{
class Program
{
static void Main(string[] args)
{
Fish f = new Fish(14, 16);
Frog g = new Frog(45, 36);
Bird b = new Bird(22, 56);
Animal[] a = new Animal[2];
a[0] = f;
a[1] = g;
a[2] = b;
a[0].Move();
a[1].Move();
a[2].Move();

}
}
}
...全文
805 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
s0705150 2012-03-08
  • 打赏
  • 举报
回复
是由于函数中出现无限递归或无限循环导致的,可以用vs调试,看看到底哪段代码出问题了!
gomoku 2012-02-29
  • 打赏
  • 举报
回复
public int X
{
get
{
return x;
}
set
{
x = ((value >= 1) && (value <= 168)) ? value : 0;
}
}
public int Y
{
get
{
return y;
}
set
{
y = ((value >= 1) && (value <= 168)) ? value : 0;
}
}
用大写会导致调用自己,进而造成堆栈溢出。
Animal[] a = new Animal[3];

110,554

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧