未处理的“System.ArgumentOutOfRangeException”类型的异常出现在 mscorlib.dll 中。 string s1 = s_txt.
usingSystem;usingSystem.Collections.Generic;usingSystem.ComponentModel;usingSystem.Da...
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
namespace three
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
这里是计算器上Backpace键的输入语句.
}
private void button19_Click(object sender, EventArgs e)
{
}
private void button22_Click(object sender, EventArgs e)
{//等于号键的输入
double d_result=0;
string s_txt = textBox1.Text;
int space = s_txt.IndexOf(' ');
string s1 = s_txt.Substring(0,space);
char operation = Convert.ToChar(s_txt.Substring((space + 1), 1));
string s2 = s_txt.Substring(space + 3);
double arg1 = Convert.ToDouble(s1);
double arg2 = Convert.ToDouble(s2);
switch (operation)
{
case '+':
d_result = arg1 + arg2;
break;
case '-':
d_result = arg1 - arg2;
break;
case '*':
d_result = arg1 * arg2;
break;
case '/':
if (arg2 == 0)
{
MessageBox.Show("错误");
}
else
{
d_result = arg1 / arg2;
}
break;
default:
MessageBox.Show("错误");
break;
}
textBox1.Text = d_result.ToString();
}
}
} 展开
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
namespace three
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
这里是计算器上Backpace键的输入语句.
}
private void button19_Click(object sender, EventArgs e)
{
}
private void button22_Click(object sender, EventArgs e)
{//等于号键的输入
double d_result=0;
string s_txt = textBox1.Text;
int space = s_txt.IndexOf(' ');
string s1 = s_txt.Substring(0,space);
char operation = Convert.ToChar(s_txt.Substring((space + 1), 1));
string s2 = s_txt.Substring(space + 3);
double arg1 = Convert.ToDouble(s1);
double arg2 = Convert.ToDouble(s2);
switch (operation)
{
case '+':
d_result = arg1 + arg2;
break;
case '-':
d_result = arg1 - arg2;
break;
case '*':
d_result = arg1 * arg2;
break;
case '/':
if (arg2 == 0)
{
MessageBox.Show("错误");
}
else
{
d_result = arg1 / arg2;
}
break;
default:
MessageBox.Show("错误");
break;
}
textBox1.Text = d_result.ToString();
}
}
} 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询