本文实例为大家分享了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) { } } }
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持。