设计如下:

代码:

using System;
using System.IO;

public partial class 四则运算 : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    public static int right = 0;
    
   
    protected void Button1_Click(object sender, EventArgs e)
    {
        int n1 = int.Parse(TextBox1.Text .Trim ());

        int n2 = int.Parse(TextBox3 .Text .Trim ());

        Char y = Convert.ToChar(TextBox2 .Text .Trim ());

       fengzhuang  con = new fengzhuang ();

        con.cl(n1, n2, y);

        if (con.result == int.Parse(TextBox4 .Text .Trim ()))
        {

            Response.Write("<script>alert('回答正确!')</script>");

            right++;

           

        }



        else
        {
            Response.Write("<script>alert('回答错误!')</script>");

          
        }
    }
    protected void Button2_Click(object sender, EventArgs e)
    {
        ListBox2.Items.Add(TextBox1.Text + TextBox2.Text + TextBox3.Text + Label1 .Text +TextBox4 .Text);


        TextBox1.Text="";

        TextBox2.Text = "";

        TextBox3.Text = "";

        TextBox4.Text = "";
    }
}

  

封装类:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

/// <summary>
///fengzhuang 的摘要说明
/// </summary>
public class fengzhuang
{
	
		//
		//TODO: 在此处添加构造函数逻辑
		//
       public char ysf;

       public int result = 0;

       public void cl(int number1, int number2, char ysf)

        {          

            if(ysf=='+')

            { 

                 result=number1+number2;

            }

            if (ysf == '-')

            {

               result=number1-number2;

            }

            if (ysf== '*')

            {

              result=number1*number2;

             }

           if (ysf == '/')

            {

              result=number1/number2;


             }

         }

 }

    

  测试: