當我嘗試在窗體類內創建窗體類的對象時,它會發生一個異常,因爲發生了stackoverflow.However,當我聲明方法內的窗體類的對象,它工作正常。代碼如下:在窗體類中的stackoverflow異常
namespace WindowsFormsApplication6
{
public partial class Form1 : Form
{
**Form1 f1 = new Form1();**//gives stackoverflow exception.......
char[] ar = new char[15];
int flag = 0, end;
double val1, val2, res;
string oprt;
public Form1()
{
InitializeComponent();
}
private void masters(object sender, EventArgs e)
{
ar[i] = char.Parse(((Button)sender).Text);
if (char.IsDigit(ar[i]))
{
if (flag != 0)
{
if (textBox1.Text == oprt)
{
textBox1.Clear();
}
}
else
{
if (end == 1)
{
textBox1.Clear();
end = 0;
}
}
Button ansbox = sender as Button;
textBox1.Text += ansbox.Text;
}
else if (char.IsSymbol(ar[i]))
{
if (textBox1.TextLength != 0)
{
val1 = double.Parse(textBox1.Text);
textBox1.Clear();
Button bt = sender as Button;
if (bt != null)
textBox1.Text = bt.Text;
oprt = bt.Text;
// dot.Enabled = true;
flag = 1;
}
}
}
private void button14_Click(object sender, EventArgs e)
{
if (textBox1.TextLength != 0)
{
val2 = double.Parse(textBox1.Text);
switch (oprt)
{
case "+": res = val1 + val2;
break;
case "-": res = val1 - val2;
break;
case "*": res = val1 * val2;
break;
case "/": res = val1/val2;
break;
}
textBox1.Text = res.ToString();
flag = 0;
end = 1;
}
}
}
}
}
+1 stackoverflow異常! – Fabian 2010-07-21 14:58:53