網站首頁 編程語言 正文
本文實例為大家分享了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#實現單位換算器_C#教程
- 下一篇:C#算法之羅馬數字轉整數_C#教程
相關推薦
- 2022-09-12 Python?argparse庫的基本使用步驟_python
- 2023-02-17 docker快速部署zabbix的方法_docker
- 2022-04-01 Python?eval()?函數看這一篇就夠了_python
- 2022-08-31 python中ndarray數組的索引和切片的使用_python
- 2023-08-01 elementui中Table切換分頁保存多選框選中的數據
- 2022-07-13 Android自定義View實現簡易畫板功能_Android
- 2023-07-18 SpringBoot中線程池初始化,并且可配置線程池參數
- 2022-05-10 Element-ui 中 Select 選擇器下拉框樣式及輸入框樣式的修改問題(背景色透明與懸停背景
- 最近更新
-
- window11 系統安裝 yarn
- 超詳細win安裝深度學習環境2025年最新版(
- Linux 中運行的top命令 怎么退出?
- MySQL 中decimal 的用法? 存儲小
- get 、set 、toString 方法的使
- @Resource和 @Autowired注解
- Java基礎操作-- 運算符,流程控制 Flo
- 1. Int 和Integer 的區別,Jav
- spring @retryable不生效的一種
- Spring Security之認證信息的處理
- Spring Security之認證過濾器
- Spring Security概述快速入門
- Spring Security之配置體系
- 【SpringBoot】SpringCache
- Spring Security之基于方法配置權
- redisson分布式鎖中waittime的設
- maven:解決release錯誤:Artif
- restTemplate使用總結
- Spring Security之安全異常處理
- MybatisPlus優雅實現加密?
- Spring ioc容器與Bean的生命周期。
- 【探索SpringCloud】服務發現-Nac
- Spring Security之基于HttpR
- Redis 底層數據結構-簡單動態字符串(SD
- arthas操作spring被代理目標對象命令
- Spring中的單例模式應用詳解
- 聊聊消息隊列,發送消息的4種方式
- bootspring第三方資源配置管理
- GIT同步修改后的遠程分支