未处理的“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();
}
}
}
展开
 我来答
timmygod
2010-11-07 · TA获得超过153个赞
知道答主
回答量:417
采纳率:0%
帮助的人:129万
展开全部
int space = s_txt.IndexOf(' ');
string s1 = s_txt.Substring(0,space);

如果space == -1 ,这个错误就来了
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式