现在的位置: 首页 > 综合 > 正文

一个简单的.NET的类的例子:华氏和摄氏,公里和英里的转换类的例子

2018年01月23日 ⁄ 综合 ⁄ 共 1119字 ⁄ 字号 评论关闭

using System;
using System.Data;
using System.Data.OleDb;

namespace convertTempAndMile
{

  public class convertTemp
  {
    private string strFrom;
    private string strTo;
    private int intTemp;

    public convertTemp(string strFromVar, string strToVar, int intTempVar)
    {
      strFrom = strFromVar;
      strTo = strToVar;
      intTemp = intTempVar;
    }

    public double convertTempRun (string strMethod, double intTempVar)
    {
      double fltConvertOK;
     
      if(strMethod == "H"){
        fltConvertOK = intTempVar * 9 / 5 + 32;
      } else if(strMethod == "S"){
        fltConvertOK = (intTempVar - 32) / 9 * 5;
      } else {
        fltConvertOK = 0;
      }

      return fltConvertOK;
    }//convertTempRun

    public double convertMilesRun (string strMethod, double intMilesVar)
    {
      double fltConvertOK;
     
      if(strMethod == "Y"){
        fltConvertOK = intMilesVar * 1.6039;
      } else if(strMethod == "G"){
        fltConvertOK = intMilesVar * 0.6214;
      } else {
        fltConvertOK = 0;
      }
      return fltConvertOK;
    }//convertMilesRun
        
  } //public class convertTemp
 
}//end namespace

 

/*

用如下的DOS命令进行编译

set indir=F:/BackUP/wwwroot/aspx/temp.cs
set outdir=F:/BackUP/wwwroot/aspx/temp.dll

csc /t:library /out:%outdir% %indir%

*/

抱歉!评论已关闭.