zoukankan      html  css  js  c++  java
  • WPF应用

    代码

       private void button1_Click(object sender, RoutedEventArgs e)
            {
                calculate sa = new calculate(int.Parse(textBox1.Text),int.Parse(textBox3.Text),textBox2.Text);
                if (sa.answer == int.Parse(textBox4.Text))
                {
                    MessageBox.Show("回答正确");
                }
                else
                {
                    MessageBox.Show("回答错误");
                
                }
     interface chapter
        {
            int answer { get; }
        }
        class calculate:chapter
        {
               private int x1;
            private int x2;
            private string Operator;
            public int result;
            public calculate(int x1, int x2, string Operator)
            {
                this.x1 = x1;
                this.x2 = x2;
                this.Operator = Operator;
           
    
            }
            public int answer
            {
                get {
    
                    if (Operator == "+")
                    {
                        result = x1 + x2;
    
                    }
                    if (Operator == "-")
                    {
    
                        result = x1 - x2;
    
                    }
                    if (Operator == "*")
                    {
    
                        result = x1 * x2;
    
                    }
                     if (Operator == "/")
                    {
    
                        result = x1 / x2;
    
                    }
                    return result;
                }
            }
    
        }
    }

     
    总结:
     
    在不同情况下运用封装的语句很容易,困难的是对设计模式的理解和运用现在正在思考如何运用。。
  • 相关阅读:
    python 操作mysql
    python多线程
    python socket 网络编程
    nginx源码编译安装
    CentOS网卡配置文件
    使用本地yum源
    ping github 请求超时
    ping github 请求超时
    设计模式-装饰器模式
    设计模式-装饰器模式
  • 原文地址:https://www.cnblogs.com/fei2/p/5043758.html
Copyright © 2011-2022 走看看