網(wǎng)站首頁(yè) 編程語(yǔ)言 正文
本文實(shí)例為大家分享了C#實(shí)現(xiàn)溫度轉(zhuǎn)換功能的具體代碼,供大家參考,具體內(nèi)容如下
界面圖
代碼
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);將字符串類型數(shù)值轉(zhuǎn)換成等效單精度浮點(diǎn)數(shù)值 ? ? ? ? ? ? ? ? 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
相關(guān)推薦
- 2022-12-24 Android設(shè)置Padding和Margin(動(dòng)態(tài)/靜態(tài))的方法實(shí)例_Android
- 2022-07-29 Python控制線程和函數(shù)超時(shí)處理_python
- 2022-09-06 python?OpenCV的imread不能讀取中文路徑問(wèn)題及解決_python
- 2022-05-25 Flutter實(shí)現(xiàn)掃二維碼功能_Android
- 2022-09-30 centos7安裝docker容器的超詳細(xì)步驟記錄_docker
- 2022-06-14 Flutter網(wǎng)絡(luò)請(qǐng)求Dio庫(kù)的使用及封裝詳解_Android
- 2022-06-15 golang?Gin上傳文件返回前端及中間件實(shí)現(xiàn)示例_Golang
- 2022-05-21 云原生技術(shù)持久化存儲(chǔ)PV與PVC_云其它
- 最近更新
-
- window11 系統(tǒng)安裝 yarn
- 超詳細(xì)win安裝深度學(xué)習(xí)環(huán)境2025年最新版(
- Linux 中運(yùn)行的top命令 怎么退出?
- MySQL 中decimal 的用法? 存儲(chǔ)小
- get 、set 、toString 方法的使
- @Resource和 @Autowired注解
- Java基礎(chǔ)操作-- 運(yùn)算符,流程控制 Flo
- 1. Int 和Integer 的區(qū)別,Jav
- spring @retryable不生效的一種
- Spring Security之認(rèn)證信息的處理
- Spring Security之認(rèn)證過(guò)濾器
- Spring Security概述快速入門(mén)
- Spring Security之配置體系
- 【SpringBoot】SpringCache
- Spring Security之基于方法配置權(quán)
- redisson分布式鎖中waittime的設(shè)
- maven:解決release錯(cuò)誤:Artif
- restTemplate使用總結(jié)
- Spring Security之安全異常處理
- MybatisPlus優(yōu)雅實(shí)現(xiàn)加密?
- Spring ioc容器與Bean的生命周期。
- 【探索SpringCloud】服務(wù)發(fā)現(xiàn)-Nac
- Spring Security之基于HttpR
- Redis 底層數(shù)據(jù)結(jié)構(gòu)-簡(jiǎn)單動(dòng)態(tài)字符串(SD
- arthas操作spring被代理目標(biāo)對(duì)象命令
- Spring中的單例模式應(yīng)用詳解
- 聊聊消息隊(duì)列,發(fā)送消息的4種方式
- bootspring第三方資源配置管理
- GIT同步修改后的遠(yuǎn)程分支