C#基础训练营 - 02 - 运算器

public partial class Form1 : Form

{

public Form1()

{

InitializeComponent();

}

public double jia(double a,double b)

{

return a + b;

}

public double jian(double a, double b)

{

return a - b;

}

public double cheng(double a, double b)

{

return a * b;

}

public double chu(double a, double b)

{

return a / b;

}

public double mo(double a, double b)

{

return a % b;

}

private void button1_Click(object sender, EventArgs e)

{

double a = 100;

double b = 50;

// string\[\] opt = new string\[\] { "+", "-", "*", "/", "%" };

// string\[\] opfun = new string\[\] { "jia", "jian", "cheng", "chu", "mo" };

string op = cmbOp.Text.Trim();

if (double.TryParse(txtA.Text, out a) && double.TryParse(txtB.Text, out b))

{

double c = 0d;

if (op == "+")

c = jia(a, b);

else if (op == "-")

c = jian(a, b);

else if (op == "*")

c = cheng(a, b);

else if (op == "/")

c = chu(a, b);

else if (op == "%")

{

c = mo(a, b);

}

else

c = 0;

MessageBox.Show($"{a}{op}{b}={c}", "运算");

}

else

{

MessageBox.Show("填写错误!");

}

}

private void Form1_Load(object sender, EventArgs e)

{

txtA.Text = "100";

txtB.Text = "50";

}

}

相关推荐
微学AI21 分钟前
一根针指向所有方向:挂谷猜想对 LLM Agent 技能-记忆架构的启示
开发语言·人工智能·架构·挂谷猜想
豆瓣鸡1 小时前
算法日记 - Day3
java·开发语言·算法
凯丨2 小时前
AI 蠕虫来了:恶意文档如何通过 Copilot for Word 自我传播?
人工智能·c#·copilot
韭菜炒鸡肝天2 小时前
VTK开发笔记(一):VTK介绍,Qt..+VSx+VTK.编译
开发语言·笔记·qt
Aaron - Wistron2 小时前
Web API C# (Furion版)带 单元测试
开发语言·后端·c#
Dxy12393102163 小时前
Python项目打包成EXE完整教程(PyInstaller实战避坑)
开发语言·python
0566464 小时前
Python康复训练——常用标准库
开发语言·python·学习
骊城英雄4 小时前
基于C#+avalonia ui实现的跨平台点胶机灌胶监控控制上位机软件
开发语言·ui·c#
吾儿良辰4 小时前
一个被BCL遗忘的高性能集合:C# CircularBuffer<T>深度解析
开发语言·windows·c#
哎呦喂我去去去4 小时前
C#实现屏幕墙:同时监控多个电脑桌面(支持Windows、信创Linux、银河麒麟、统信UOS)
linux·windows·c#