求助C#制作计算器,怎么算不出来 调试一下。comboYunSfu,这是个combobox么?comboYunSfu.ToString()得到的是类型的名字。你需要写switch (comboYunSfu.Text.Trim()) 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 switch (comboYunSfu.ToString())comboYunSfu 你这个只是一个下拉控件(如果没猜错的话)的对象~他还有text属性是当前显示的值~ 断点调试,看comboYunSfu.ToString()是多少? switch (comboYunSfu.ToString())这里有问题,你自己单步调试就知道啦帮你改一下 if (textBox1.Text == "" || comboBox1.Text == "" || textBox2.Text == "") { MessageBox.Show("不能有空值", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); } else { double one = double.Parse(textBox1.Text); double two = double.Parse(textBox2.Text); switch (comboBox1.text) { case "+": label4.Text= Convert.ToString(one + two); break; case "-": label4.Text = Convert.ToString(one - two); break; } } string.IsNullOrEmpty(txtfirstcount.Text)单步跟踪调试值public class Operation { private double _numberA = 0; private double _numberB = 0; public double NumberA { get { return _numberA; } set { _numberA = value; } } public double NumberB { get { return _numberB; } set { _numberB = value; } } public virtual double GetResult() { double result = 0; return result; } public static string checkNumberInput(string currentNumber, string inputString) { string result = ""; if (inputString == ".") { if (currentNumber.IndexOf(".") < 0) { if (currentNumber.Length == 0) result = "0" + inputString; else result = currentNumber + inputString; } } else if (currentNumber == "0") { result = inputString; } else { result = currentNumber + inputString; } return result; } } class OperationAdd : Operation { public override double GetResult() { double result = 0; result = NumberA + NumberB; return result; } } class OperationSub : Operation { public override double GetResult() { double result = 0; result = NumberA - NumberB; return result; } } class OperationMul : Operation { public override double GetResult() { double result = 0; result = NumberA * NumberB; return result; } } class OperationDiv : Operation { public override double GetResult() { double result = 0; if (NumberB == 0) throw new Exception("除数不能为0。"); result = NumberA / NumberB; return result; } } class OperationSqr : Operation { public override double GetResult() { double result = 0; result = NumberB * NumberB; return result; } } class OperationSqrt : Operation { public override double GetResult() { double result = 0; if (NumberB < 0) throw new Exception("负数不能开平方根。"); result = Math.Sqrt(NumberB); return result; } } class OperationReverse : Operation { public override double GetResult() { double result = 0; result = -NumberB; return result; } } public class OperationFactory { public static Operation createOperate(string operate) { Operation oper = null; switch (operate) { case "+": { oper = new OperationAdd(); break; } case "-": { oper = new OperationSub(); break; } case "*": { oper = new OperationMul(); break; } case "/": { oper = new OperationDiv(); break; } case "sqr": { oper = new OperationSqr(); break; } case "sqrt": { oper = new OperationSqrt(); break; } case "+/-": { oper = new OperationReverse(); break; } } return oper; } private void buttonAdd_Click(object sender, EventArgs e) { if (txtShow.Text != "") { oper = OperationFactory.createOperate(((Button)sender).Text); oper.NumberA = Convert.ToDouble(txtShow.Text); bOperate = true; } } private void buttonEqual_Click(object sender, EventArgs e) { if (txtShow.Text != "") { if (((Button)sender).Text != "=") { oper = OperationFactory.createOperate(((Button)sender).Text); } oper.NumberB = Convert.ToDouble(txtShow.Text); txtShow.Text = oper.GetResult().ToString(); bOperate = true; } } 学会用 .toString().Trim() 和 convertInt32及转换类的方法............. switch (comboYunSfu.ToString())这句有问题,其实只要简单调试一下就会发现。 switch (comboYunSfu.SelectedText.ToString()) function调用? 关于ASP中的RegularExpresionValidator(正则表达式)控件使用,求救 为什么图片不能显示 向动网7.1模拟发帖,返回错误页面,抓包分析无果,望指教 关于字符串拆分函数的参数 有没有人使用过FtpWebRequest和FtpWebResponse,急需例子。调试成功一定给分 关于读取别人写的dll里面的方法和属性,不知道可以实现吗? 如何選中DATAGRID的一行,而不是一個單元格 类的实例化值变动 重复绑定问题 求助。打开项目文件提示错误. C# WEB里的Classes是哪定义的
他还有text属性是当前显示的值~
这里有问题,你自己单步调试就知道啦
帮你改一下
if (textBox1.Text == "" || comboBox1.Text == "" || textBox2.Text == "")
{
MessageBox.Show("不能有空值", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
else
{
double one = double.Parse(textBox1.Text);
double two = double.Parse(textBox2.Text); switch (comboBox1.text)
{
case "+":
label4.Text= Convert.ToString(one + two);
break;
case "-":
label4.Text = Convert.ToString(one - two);
break;
}
}
单步跟踪调试值
public class Operation
{
private double _numberA = 0;
private double _numberB = 0;
public double NumberA
{
get
{
return _numberA;
}
set
{
_numberA = value;
}
}
public double NumberB
{
get
{
return _numberB;
}
set
{
_numberB = value;
}
}
public virtual double GetResult()
{
double result = 0;
return result;
}
public static string checkNumberInput(string currentNumber, string inputString)
{
string result = "";
if (inputString == ".")
{
if (currentNumber.IndexOf(".") < 0)
{
if (currentNumber.Length == 0)
result = "0" + inputString;
else
result = currentNumber + inputString;
}
}
else if (currentNumber == "0")
{
result = inputString;
}
else
{
result = currentNumber + inputString;
} return result;
}
}
class OperationAdd : Operation
{
public override double GetResult()
{
double result = 0;
result = NumberA + NumberB;
return result;
}
}
class OperationSub : Operation
{
public override double GetResult()
{
double result = 0;
result = NumberA - NumberB;
return result;
}
}
class OperationMul : Operation
{
public override double GetResult()
{
double result = 0;
result = NumberA * NumberB;
return result;
}
}
class OperationDiv : Operation
{
public override double GetResult()
{
double result = 0;
if (NumberB == 0)
throw new Exception("除数不能为0。");
result = NumberA / NumberB;
return result;
}
}
class OperationSqr : Operation
{
public override double GetResult()
{
double result = 0;
result = NumberB * NumberB;
return result;
}
}
class OperationSqrt : Operation
{
public override double GetResult()
{
double result = 0;
if (NumberB < 0)
throw new Exception("负数不能开平方根。");
result = Math.Sqrt(NumberB);
return result;
}
}
class OperationReverse : Operation
{
public override double GetResult()
{
double result = 0;
result = -NumberB;
return result;
}
}
public class OperationFactory
{
public static Operation createOperate(string operate)
{
Operation oper = null;
switch (operate)
{
case "+":
{
oper = new OperationAdd();
break;
}
case "-":
{
oper = new OperationSub();
break;
}
case "*":
{
oper = new OperationMul();
break;
}
case "/":
{
oper = new OperationDiv();
break;
}
case "sqr":
{
oper = new OperationSqr();
break;
}
case "sqrt":
{
oper = new OperationSqrt();
break;
}
case "+/-":
{
oper = new OperationReverse();
break;
}
} return oper;
}
private void buttonAdd_Click(object sender, EventArgs e)
{
if (txtShow.Text != "")
{
oper = OperationFactory.createOperate(((Button)sender).Text); oper.NumberA = Convert.ToDouble(txtShow.Text); bOperate = true;
}
}
private void buttonEqual_Click(object sender, EventArgs e)
{
if (txtShow.Text != "")
{
if (((Button)sender).Text != "=")
{
oper = OperationFactory.createOperate(((Button)sender).Text);
}
oper.NumberB = Convert.ToDouble(txtShow.Text);
txtShow.Text = oper.GetResult().ToString();
bOperate = true;
}
}
这句有问题,其实只要简单调试一下就会发现。