C#实现温度转换功能
作者:安静点DGC 时间:2021-10-06 22:54:18
本文实例为大家分享了C#实现温度转换功能的具体代码,供大家参考,具体内容如下
界面图
代码
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace WindowsFormsApplication4
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
float x;
double y;
try
{
//Single.Parse(textBox1.Text);将字符串类型数值转换成等效单精度浮点数值
x = Single.Parse(textBox1.Text);
y = getValue(x);
label2.Text = "" + y;
}
catch (MyException ee)
{
label2.Text = ee.Message;
}
catch (FormatException ee) {
label2.Text = ee.Message;
}
}
private double getValue(float x)
{
double y;
if (x < -273.15f) throw new MyException();
y = x * 1.8f + 32;
return y;
}
class MyException : ApplicationException {
public MyException() : base("温度超出范围") {
}
}
private void textBox1_TextChanged(object sender, EventArgs e)
{
}
}
}
来源:https://blog.csdn.net/qq_26925297/article/details/80617762
标签:C#,温度转换
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
可视化Swing中JTable控件绑定SQL数据源的两种方法深入解析
2023-11-28 19:13:58
![](https://img.aspxhome.com/file/2023/3/60283_0s.jpg)
java文件操作之Path,Paths,Files
2023-11-19 15:34:34
c++中的string常用函数用法总结
2023-11-02 16:44:02
Java的super关键字与instanceof运算符使用方法
2022-02-18 10:02:22
springboot 使用QQ邮箱发送邮件的操作方法
2022-03-03 14:36:22
![](https://img.aspxhome.com/file/2023/8/62218_0s.png)
swagger添加权限验证保证API(接口)安全性(两种方法)
2023-11-27 18:58:33
![](https://img.aspxhome.com/file/2023/5/60255_0s.png)
解决javac不是内部或外部命令,也不是可运行程序的报错问题
2022-07-13 22:39:25
![](https://img.aspxhome.com/file/2023/3/66623_0s.jpg)
深入理解Spring AOP
2023-02-09 15:14:40
浅谈Java线程间通信之wait/notify
2022-06-09 11:26:19
![](https://img.aspxhome.com/file/2023/7/68527_0s.jpg)
教你使用idea搭建ssm详细教程(Spring+Spring Mvc+Mybatis)
2021-09-23 12:37:42
![](https://img.aspxhome.com/file/2023/6/62736_0s.png)
获取Java线程转储的常用方法(推荐)
2023-05-15 02:30:19
![](https://img.aspxhome.com/file/2023/8/61248_0s.png)
SpringBoot中的HATEOAS详情
2022-12-27 03:12:31
Java中synchronized的几种使用方法
2023-06-19 16:33:28
![](https://img.aspxhome.com/file/2023/8/62228_0s.webp)
浅谈Spring中Bean的作用域、生命周期
2023-11-14 02:44:21
![](https://img.aspxhome.com/file/2023/7/59567_0s.png)
java中方法递归的简单示例
2022-11-25 11:45:12
![](https://img.aspxhome.com/file/2023/1/66041_0s.png)
Mybatis的几种传参方式详解
2021-12-08 15:35:53
常用json与javabean互转的方法实现
2023-01-07 14:24:19
![](https://img.aspxhome.com/file/2023/7/63737_0s.png)
JDBC实现学生管理系统
2023-01-22 13:22:19
C#计算矩阵的逆矩阵方法实例分析
2021-11-06 18:24:29
![](https://img.aspxhome.com/file/2023/7/69197_0s.png)
使用eclipse创建java项目的方法
2022-10-15 04:41:00
![](https://img.aspxhome.com/file/2023/0/64010_0s.jpg)