zoukankan      html  css  js  c++  java
  • 封装,策略,Asp换脸

    封装、策略

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    
    namespace 算
    {
        public interface Isuan
        {
             int calculate(int a, int b);
        }
        public  class add : Isuan
        {
            public int calculate(int a,int b) 
            {
                return a + b;
            }
        }
        public class sub : Isuan 
        {
            public int calculate(int a, int b)
            {
                return a - b;
            }
        }
        public class mal : Isuan 
        {
            public int calculate(int a, int b) 
            {
                return a * b;
            }
        }
        public class div : Isuan 
        {
            public int calculate(int a, int b)
            {
                return a / b;
            }
        }
    }
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.IO;
    
    namespace 算
    {
        class fuhao
        {
            private Isuan fh;
            public fuhao(string a)
            {
                switch(a)
                {
                    case"+":
                        fh = new add();
                        break;
                    case "-":
                        fh = new sub();
                        break;
                    case "*":
                        fh = new mal();
                        break;
                    case "/":
                        fh = new div();
                        break;
                }
            }
            public int jisuan(int a, int b) 
            {
                return fh.calculate(a, b);
            }
    
        }
    }
    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Linq;
    using System.Text;
    using System.Windows.Forms;
    using System.IO;
    
    namespace 算
    {
        public partial class Form1 : Form
        {
            public Form1()
            {
                InitializeComponent();
            }
            private int An;
            private void button2_Click(object sender, EventArgs e)
            {
                this.Close();
            }
    
            private void button1_Click(object sender, EventArgs e)
            {
    fuhao clacuter = new fuhao(comboBox1.Text);
                An = clacuter.jisuan(int.Parse(textBox1.Text), int.Parse(textBox2.Text));
    if (textBox3.Text == An.ToString()) { MessageBox.Show("回答正确!"); } else { MessageBox.Show("回答错误!"); } textBox1.Clear(); textBox2.Clear(); comboBox1.Text = ""; textBox3.Clear(); } private void textBox3_KeyDown(object sender, KeyEventArgs e) { if (e.KeyCode == Keys.Enter) { fuhao clacuter = new fuhao(comboBox1.Text);  An = clacuter.jisuan(int.Parse(textBox1.Text), int.Parse(textBox2.Text)); if (textBox3.Text == An.ToString()) { MessageBox.Show("回答正确!"); } else { MessageBox.Show("回答错误!"); } textBox1.Clear(); textBox2.Clear(); comboBox1.Text = ""; textBox3.Clear(); } } } }


    asp换脸

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    
    /// <summary>
    ///fuhao 的摘要说明
    /// </summary>
    public class fuhao
    {
        private Isuan s;
        public fuhao(string a)
        {
            switch (a)
            {
                case"+":
                    s = new add();
                    break;
                case "-":
                    s = new sub();
                    break;
                case "*":
                    s = new cml();
                    break;
                case "/":
                    s = new div();
                    break;
            }
        }
        public int suan(int a, int b) 
        {
            return s.cla(a,b);
        }
      
    }
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    
    /// <summary>
    ///suan 的摘要说明
    /// </summary>
    
    
         public interface Isuan 
        {
             int cla(int a, int b);
        }
        public class add:Isuan
        {
            public int cla(int a, int b) 
            {
                return a + b;
            }
        }
        public class sub:Isuan
        {
            public int cla(int a, int b)
            {
                return a - b;
            }
        }
        public class cml:Isuan
        {
            public int cla(int a, int b)
            {
                return a * b;
            }
        }
        public class div:Isuan
        {
            public int cla(int a, int b)
            {
                return a / b;
            }
        }
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    
    public partial class _Default : System.Web.UI.Page
    {
        private int An;
        protected void Page_Load(object sender, EventArgs e)
        {
    
        }
        protected void Button1_Click(object sender, EventArgs e)
        {
            fuhao b = new fuhao(TextBox2.Text);
            An=b.suan(int.Parse(TextBox1.Text),int.Parse(TextBox3.Text));
            if (TextBox4.Text == An.ToString())
            {
                Response.Write("回答正确!");
            }
            else 
            {
                Response.Write("回答错误!");
            }
        }
    }

  • 相关阅读:
    UUID工具类
    jax-rs 标准以及 结合 resteasy的使用
    Mina.Net实现的断线重连
    Mina.Net实现的UDP协议消息收发Demo
    MySql 比Replace Into更适合的用法,外加SqlServer的方式。
    MySql【Insert Select Not Exist】判断记录再添加值的方案
    MySql中存储过程中的@变量总是无法执行,提示Parameter '@XXX' must be defined
    Go语言使用Beego的ORM插入Mysql后,时区不一致的解决方案
    Go语言中Path包用法
    C#(WPF和WinForm)在普通类中调用到主线程的方法,SynchronizationContext的用法。
  • 原文地址:https://www.cnblogs.com/fanxiaotian/p/5002667.html
Copyright © 2011-2022 走看看