namespace _2
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
} private void Form1_Load(object sender, EventArgs e)
{ } private void button1_Click(object sender, EventArgs e)
{
int div = int.Parse(textBox1.Text) / int.Parse(textBox2.Text);
textBox3.Text = div.ToString(); } }
}总是不成功啊
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
} private void Form1_Load(object sender, EventArgs e)
{ } private void button1_Click(object sender, EventArgs e)
{
int div = int.Parse(textBox1.Text) / int.Parse(textBox2.Text);
textBox3.Text = div.ToString(); } }
}总是不成功啊
解决方案 »
- C#操作Excel
- Response.Write("<script>window.open();</script>");不传值?
- vs2005 中 web应用程序如何打包 ?
- C#无边框窗体在WINDOWS任务栏中无法显示右键菜单
- 求助?为什么无法改变变量内容
- 问一个关于数据类型转换的问题,请达人帮忙解惑啊!!!
- 诚心求教,希望各位高手给我指点一二!
- WCF,初学,什么是客户端代理类
- 有没有人推荐个 类似于SpreadSheet的开源的表格控件啊?
- 做一个淘宝标题优化软件,淘宝卖家用户购买软件之后,怎样通过淘宝卖家用户账号获取该用户的appkey和sessionkey
- 关于GridView控件绑定数据
- xml树形结构操作问题
{
MessageBox.Show("不能为空", "", MessageBoxButtons.YesNo)
}
else if(int.Parse(textBox2.Text)==0)
{
MessageBox.Show("除数不能为0", "", MessageBoxButtons.YesNo)
}
int i = 5f;
int j = 0/ (i-5);
Console.WriteLine(j); catch(DivideByZeroException e)
{
System.Console.WriteLine("零不能作为除数!异常值为:\n{0}",e);
}
catch(Exception e)
{
System.Console.WriteLine("并非\''零作为除数引发的异常\"!异常值为:\n{0}",e);
} int.TryParse先取值判断
这样控制台的好控制我用textBox.Text 来接收 数字怎么就做不好呢
虽然道理一样的
namespace _2
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
} private void Form1_Load(object sender, EventArgs e)
{ } private void button1_Click(object sender, EventArgs e)
{
int div = int.Parse(textBox1.Text) / int.Parse(textBox2.Text);
textBox3.Text = div.ToString();
try(DivideByZeroException e)
{
if (int.Parse(textBox2.Text) == 0)
} catch(Exception e)
{
MessageBox.Show("除以0异常");
}; }
}
}
{
if (int.Parse(textBox2.Text) == 0)
} catch(Exception e)
{
MessageBox.Show("除以0异常");
};
private void button1_Click(object sender, EventArgs e)
{
try()
{ int div = int.Parse(textBox1.Text) / int.Parse(textBox2.Text);
textBox3.Text = div.ToString();
if (int.Parse(textBox2.Text) == 0)
}
catch(DivideByZeroException ex)
{
MessageBox.Show("不能除以0");
}
catch(Exception e)
{
MessageBox.Show("除以0异常");
}; }
{
try{
int div = int.Parse(textBox1.Text) / int.Parse(textBox2.Text);
textBox3.Text = div.ToString();
}
catch(DivideByZeroException ex)
{
MessageBox.Show("不能除以0");
}
}
string str;
private void button1_Click(object sender, EventArgs e)
{
str=textbox2.text.trim()
if(str="0" or int.parse(textbox2.text)==0)
Messagebox.show("除数不能为0!","Error");
else
int div=int.parse(textbox1.text)/int.parse(textbox2.text);
textbox3.text =div.tostring();
}其他的不变,看行不
if(str="0" || int.parse(textbox2.text)==0)
如果实在憋得慌非要自定义错误,那就这样:if(textBox2.Text.Trim()=="0")
throw new DivideByZeroException("除数不能为0");
if(int.Parse(textBox2.Text.Trim()))
throw new DivideByZeroException("除数不能为0");