using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;namespace 计算器
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
} private void textBox2_TextChanged(object sender, EventArgs e)
{ } private void button1_Click(object sender, EventArgs e)
{
string str1 = this.textBox1.Text;
string str2 = this.textBox2.Text;
unchecked
{
decimal i= decimal.Parse(str1);
decimal j = decimal.Parse(str2); string oper = this.comboBox1.Text;
}
}
private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
{
decimal result = 0;
switch (oper)
{
case "+": result = i + j; break; case "-": result =i - j; break;
case "*": result = i* j; break;
case "%": result = i & j; break;
}
this.textBox3.Text = result.ToString;
{
}
}
}
} 能帮我看看 这个C# 哪里错了么 调试有问题 说是找不到i j 还有oper 谢谢了
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;namespace 计算器
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
} private void textBox2_TextChanged(object sender, EventArgs e)
{ } private void button1_Click(object sender, EventArgs e)
{
string str1 = this.textBox1.Text;
string str2 = this.textBox2.Text;
unchecked
{
decimal i= decimal.Parse(str1);
decimal j = decimal.Parse(str2); string oper = this.comboBox1.Text;
}
}
private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
{
decimal result = 0;
switch (oper)
{
case "+": result = i + j; break; case "-": result =i - j; break;
case "*": result = i* j; break;
case "%": result = i & j; break;
}
this.textBox3.Text = result.ToString;
{
}
}
}
} 能帮我看看 这个C# 哪里错了么 调试有问题 说是找不到i j 还有oper 谢谢了
{
case "+": result = i + j; break; case "-": result =i - j; break;
case "*": result = i* j; break;
case "%": result = i & j; break;
}
this.textBox3.Text = result.ToString; 哪里来的oper i j?
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms; namespace 计算器
{
public partial class Form1 : Form
{
public string result;
public string i;
public string j;
public Form1()
{
InitializeComponent();
} private void textBox2_TextChanged(object sender, EventArgs e)
{ } private void button1_Click(object sender, EventArgs e)
{
string str1 = this.textBox1.Text;
string str2 = this.textBox2.Text;
unchecked
{
decimal i= decimal.Parse(str1);
decimal j = decimal.Parse(str2); string oper = this.comboBox1.Text;
}
}
private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
{
decimal result = 0;
switch (oper)
{
case "+": result = i + j; break; case "-": result =i - j; break;
case "*": result = i* j; break;
case "%": result = i & j; break;
}
this.textBox3.Text = result.ToString;
{
}
}
}
}
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;namespace W
{
public partial class lblExplain : Form
{
public lblExplain()
{
InitializeComponent();
} private void btnTo_Click(object sender, EventArgs e)
{
string str1 = this.textBox1.Text;
string str2 = this.textBox2.Text;
unchecked
{
decimal i = decimal.Parse(str1);
decimal j = decimal.Parse(str2);
decimal result = i + j;
this.textBox3.Text = result.ToString();
}
} private void textBox2_TextChanged(object sender, EventArgs e)
{ }
}
} 那这个怎么没问题啊 为什么啊 老师们
{
public partial class Form1 : Form
{
private void button1_Click(object sender, EventArgs e)
{
string str1 = this.textBox1.Text;
string str2 = this.textBox2.Text;
unchecked
{
decimal i= decimal.Parse(str1);
decimal j = decimal.Parse(str2);
string oper = this.comboBox1.Text;
}
}
private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
{
decimal result = 0;
switch (oper)
{
case "+": result = i + j; break; case "-": result =i - j; break;
case "*": result = i* j; break;
case "%": result = i & j; break;
}
this.textBox3.Text = result.ToString;
{
}
}
}
} 你的i和j是在button1_Click()中定义的,这个不是全局变量,要想在其他方法中使用,就必须定义成全局变量,那么你就应该在public partial class Form1 : Form
{ 在这里定义}
public partial class Form1 : Form
{ decimal i,j; }
然后在各个方法中使用i和j就可以了。
这个 又能委托 什么的
public string i;
public string j;
public Form1()
{
InitializeComponent();
} private void textBox2_TextChanged(object sender, EventArgs e)
{ } private void button1_Click(object sender, EventArgs e)
{
string str1 = this.textBox1.Text;
string str2 = this.textBox2.Text;
unchecked
{
decimal i= decimal.Parse(str1);
decimal j = decimal.Parse(str2); string oper = this.comboBox1.Text;
}
}
private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
{
decimal result = 0;
switch (oper)
{
case "+": result = i + j; break; case "-": result =i - j; break;
case "*": result = i* j; break;
case "%": result = i & j; break;
}
this.textBox3.Text = result.ToString;
{
}
}
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms; namespace 计算器
{
public partial class Form1 : Form
{
//这里定义全局变量
decimal i;
decimal j;
string oper ; public Form1()
{
InitializeComponent();
} private void textBox2_TextChanged(object sender, EventArgs e)
{ } private void button1_Click(object sender, EventArgs e)
{
string str1 = this.textBox1.Text;
string str2 = this.textBox2.Text;
unchecked
{
i= decimal.Parse(str1);
j = decimal.Parse(str2); oper = this.comboBox1.Text;
}
}
private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
{
decimal result = 0;
switch (oper)
{
case "+": result = i + j; break; case "-": result =i - j; break;
case "*": result = i* j; break;
case "%": result = i & j; break;
}
this.textBox3.Text = result.ToString;
{
}
}
}
}
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms; namespace 计算器
{
public partial class Form1 : Form
{
//这里定义全局变量
decimal i;
decimal j;
string oper ; public Form1()
{
InitializeComponent();
} private void textBox2_TextChanged(object sender, EventArgs e)
{ } private void button1_Click(object sender, EventArgs e)
{
string str1 = this.textBox1.Text;
string str2 = this.textBox2.Text;
unchecked
{
i= decimal.Parse(str1);
j = decimal.Parse(str2); oper = this.comboBox1.Text;
switch (oper)
{
case "+": result = i + j; break; case "-": result =i - j; break;
case "*": result = i* j; break;
case "%": result = i & j; break;
}
this.textBox3.Text = result.ToString;
}
}
private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
{
decimal result = 0;
unchecked
{
i= decimal.Parse(str1);
j = decimal.Parse(str2); oper = this.comboBox1.Text;
switch (oper)
{
case "+": result = i + j; break; case "-": result =i - j; break;
case "*": result = i* j; break;
case "%": result = i & j; break;
}
this.textBox3.Text = result.ToString;
}
}
}
}