C#如何用空字符 第一次来 求教
/*****以下是我用try+catch做的一个简单的format 计算器 关键在switch..default 那里
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace 计算器
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void checkedListBox1_SelectedIndexChanged(object sender, EventArgs e)
{
}
private void Form1_Load(object sender, EventArgs e)
{
}
private void button1_Click(object sender, EventArgs e)
{
try
{
float a = int.Parse(bjk1.Text);//声明三个变量 并类型转化成int型
float b = int.Parse(bjk2.Text);//
float c;
switch (choice.Text) //做选择
{
case "+":
c = a + b;
break;
case "-":
c = a - b;
break;
case "*":
c = a * b;
break;
case "/":
c = a / b;
break;
default: //如何让这里变成空字符 为空就行 而不是显示0 c = 0.00F;
break;
}
bjk3.Text = c.ToString();
}
/*************格式错误***********************/
catch (FormatException nub1)
{
MessageBox.Show(nub1.Message);
return;
}
/***********数据溢出***********************/
catch (OverflowException nub2)
{
MessageBox.Show(nub2.Message);
return;
}
/*************被0除*********************/
catch (DivideByZeroException nub3)
{
MessageBox.Show(nub3.Message);
return;
}
/*************其它可能*********************/
catch (Exception nub4)
{
MessageBox.Show(nub4.Message);
return;
}
}
}
}
[解决办法]
}
}
[解决办法]
bool isNull = false;
.
.
.
default:
isNull = true;
break;
if (isNull)
{
bjk3.Text = "";
} else
{
bjk3.Text = c.toSting();
}