mvp类型转换问题

时间:2011-05-09 10:08:31

标签: c# mvp

我在下面有一个简单的mvp演示:

public partial class _Default : System.Web.UI.Page, IView
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }

    #region IView Members

    public string RadiusText
    {
        get { return TextRadius.Text; }
        set { TextRadius.Text = value; }
    }

    public string ResultText
    {
        get { return LabelResult.Text; }
        set { LabelResult.Text = value; }
    }

    #endregion
    protected void ButtonResult_Click(object sender, EventArgs e)
    {
        CPresenter presenter = new CPresenter(this);
        presenter.CalculateCircleArea();
    }
}

/// <summary>
/// interface view 1
/// </summary>
public interface ICircleModel
{
    double getArea(double radius);
}

public class CModel : ICircleModel
{
    public CModel() { }

    #region ICircleModel Members

    public double getArea(double radius)
    {
        return Math.PI * radius * radius;
    }

    #endregion
}

/// <summary>
/// interface view 2
/// </summary>
public interface IView
{
    string RadiusText { get; set; }
    string ResultText { get; set; }
}


/// <summary>
/// Summary description for Presenter
/// </summary>
public class CPresenter
{
    IView mview;
    public CPresenter(IView view)
    {
        mview = view;
    }
    public double CalculateCircleArea()
    {
        CModel model = new CModel();
        mview.ResultText = model.getArea(Double.Parse(mview.RadiusText)).ToString();
        return mview.ResultText.ToString();
    }
}

我得到的错误是:

错误1无法将类型'string'隐式转换为'double'

1 个答案:

答案 0 :(得分:1)

当方法签名将double定义为retrurn参数时,CPresenter类中的CalculateCircleArea()方法将返回一个字符串。将return参数更改为字符串或从方法中返回double。