ASP.net

ASP.net

后台代码
protected void Button1_Click(object sender, EventArgs e) { ric.X =double .Parse( TextBox1.Text); ric.Y =double .Parse( TextBox3.Text); ric.fuhao = DropDownList1.SelectedValue; ric.result = result; ric.Add(); ric.Sub(); ric.Mul(); ric.Div(); if (TextBox4.Text == ric.result.ToString()) { Response.Write("<script>alert('回答正确')</script>"); } else { Response.Write("<script>alert('回答错误')</script>"); } } protected void DropDownList1_TextChanged(object sender, EventArgs e) { string fuhao = DropDownList1.SelectedValue; switch (fuhao) { case"+": DropDownList1.SelectedValue = "+"; break; case"-": DropDownList1.SelectedValue = "-"; break; case"*": DropDownList1.SelectedValue = "*"; break; case"/": DropDownList1.SelectedValue = "/"; break; default: break; } }

添加一个新类Richnone复制代码

public class Richnone
{
    public string fuhao;//计算符号
    public double result;


    private double x;//第一个数
    public double X
    {
        get { return x; }
        set { x = value; }
    }
    private double y;//第二个数
    public double Y
    {
        get { return y; }
        set { y = value; }
    }
    public void Add()//加法
    {
        if (fuhao == "+")
        {
            result = X + Y;
        }
    }
    public void Sub()
    {
        if (fuhao == "-")
        {
            result = X - Y;
        }
    }
    public void Mul()
    {
        if (fuhao == "*")
        {
            result = X * Y;
        }
    }
    public void Div()
    {
        if (fuhao == "/")
        {
            result = X / Y;
        }
    }
       
}

 

 

   

截图
posted @ 2015-11-30 18:42  木木夕℡  阅读(168)  评论(1编辑  收藏  举报