转载:https://blog.youkuaiyun.com/dust__/article/details/102980510

namespace 计算器
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
}
private void button1_Click(object sender, EventArgs e)
{
double num1 = Convert.ToDouble(textBox1.Text);
double num2 = Convert.ToDouble(textBox2.Text);
string type = comboBox1.SelectedItem .ToString();
if (type == "+")
{
double num = num1 + num2;
string num3 = num.ToString();
label1.Text = num3;
}
if (type=="-")
{
double num = num1 - num2;
string num3 = num.ToString();
label1.Text = num3;
}
if (type=="×")
{
double num = num1 * num2;
string num3 = num.ToString();
label1.Text = num3;
}
if (type=="÷")
{
double num = num1 / num2;
string num3 = num.ToString();
label1.Text = num3;
}
if (type=="%")
{
double num = num1 % num2;
string num3 = num.ToString();
label1.Text = num3;
}
}
}
}
本文介绍了一个使用C#编写的简单计算器应用程序。该程序能够进行基本的算术运算,包括加、减、乘、除和取模操作。通过文本框输入数字,选择运算类型,点击按钮即可显示结果。
6414

被折叠的 条评论
为什么被折叠?



