temperature.cs

来自「C#设计模式随书源代码.全书一共介绍了23种设计模式」· CS 代码 · 共 37 行

CS
37
字号
using System;

namespace CalcTemp
{
	/// <summary>
	/// Summary description for Temperature.
	/// </summary>
	public class Temperature 	{
		private float temp, newTemp;
		//-------------
		public Temperature(string thisTemp) 		{
			temp = Convert.ToSingle(thisTemp);
		}
		//-------------
		public string getConvTemp(bool celsius){
		if (celsius) 
			return getCels();
		else
			return getFahr();
		}
		//-------------
		private string getCels() {
			newTemp= 5*(temp-32)/9;
			return newTemp.ToString() ;
		}
		//-------------
		private string getFahr() {
			newTemp = 9*temp/5 + 32;
			return Convert.ToString(newTemp) ;
		}	
		public string getKelvin() {
			float ttemp =  (float)(5*(temp - 32)/9 +273.16);
			return ttemp.ToString ();
		}
	}
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?