题目:一个新组件,实现功能摄氏温度到华氏温度的转换,公里到英里的转换等,一些转换公式略下面是我写的内容:
using System;
using System.ComponentModel;
using System.Collections;
using System.Diagnostics;namespace wrok
......
public void tohc (double t_oc)  
{
double hc;
hc=t_oc*(9/5)+32;
return hc;
        }
public void tooc (double t_hc)
{
double oc;
oc=(t_hc-32)*(5/9);
return oc;
}
public void tomile (double t_km)
{
double mile;
mile=Round((t_km*1.6039),4);
return mile;
}
public void tokm (double t_mile)
{
double km;
km=Round((0.6214*t_mile));
return km;
}
这样写为什么错了

解决方案 »

  1.   

    完整的如下:using System;
    using System.ComponentModel;
    using System.Collections;
    using System.Diagnostics;namespace wrok
    {
    /// <summary>
    /// Component1 的摘要说明。
    /// </summary>
    public class Component1 : System.ComponentModel.Component
    {
    /// <summary>
    /// 必需的设计器变量。
    /// </summary>
    private System.ComponentModel.Container components = null; public Component1(System.ComponentModel.IContainer container)
    {
    ///
    /// Windows.Forms 类撰写设计器支持所必需的
    ///
    container.Add(this);
    InitializeComponent(); //
    // TODO: 在 InitializeComponent 调用后添加任何构造函数代码
    //
    } public Component1()
    {
    ///
    /// Windows.Forms 类撰写设计器支持所必需的
    ///
    InitializeComponent(); //
    // TODO: 在 InitializeComponent 调用后添加任何构造函数代码
    //
    } /// <summary> 
    /// 清理所有正在使用的资源。
    /// </summary>
    protected override void Dispose( bool disposing )
    {
    if( disposing )
    {
    if(components != null)
    {
    components.Dispose();
    }
    }
    base.Dispose( disposing );
    } public void tohc (double t_oc)  
    {
    double hc;
    hc=t_oc*(9/5)+32;
    return hc;
            }
    public void tooc (double t_hc)
    {
    double oc;
    oc=(t_hc-32)*(5/9);
    return oc;
    }
    public void tomile (double t_km)
    {
    double mile;
    mile=Round((t_km*1.6039),4);
    return mile;
    }
    public void tokm (double t_mile)
    {
    double km;
    km=Round((0.6214*t_mile),4);
    return km;
    }
    #region 组件设计器生成的代码
    /// <summary>
    /// 设计器支持所需的方法 - 不要使用代码编辑器修改
    /// 此方法的内容。
    /// </summary>
    private void InitializeComponent()
    {
    components = new System.ComponentModel.Container();
    }
    #endregion
    }
    }调用页面:
    private void Button1_Click(object sender, System.EventArgs e)
    {
     Label1.Text=tooc((double)TextBox1.Text);
    } private void Button2_Click(object sender, System.EventArgs e)
    {
      Label2.Text=tohc((double)TextBox2.Text);
    } private void Button3_Click(object sender, System.EventArgs e)
    {
      Label3.Text=tomile((double)TextBox3.Text);
    } private void Button4_Click(object sender, System.EventArgs e)
    {
     Label4.Text=tokm((double)TextBox4.Text);
    }
      

  2.   

    void类型是没有返回值的,把void去掉然后定义函数类型·
      

  3.   


    Label4.Text=tokm((double)TextBox4.Text);
    这样转换为什么不对?
      

  4.   

    还有round要using 哪个东西
    分不够可以再加