zoukankan      html  css  js  c++  java
  • C# 事件

    using System;
    using System.Collections;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Linq;
    using System.Net.NetworkInformation;
    using System.Text;
    using System.Threading.Tasks;
    namespace CSharpStudy
    {


        class Program
        {
            static void Main(string[] args)
            {
                Calculator calculator = new Calculator();
                CalculatorManager calculatorManager = new CalculatorManager();
                calculator.MyCalculate += calculatorManager.Add;
                calculator.Calculate(2100);
                calculator.MyCalculate += calculatorManager.Substract;
                calculator.Calculate(100100);
                Console.ReadKey();
            }

        }
        public class Calculator
        {
            public delegate void CalculateEventhandler(object sender, CalculateEventArgs e);
            public event CalculateEventhandler MyCalculate;
            public virtual void OnCalculate(CalculateEventArgs e)
            {
                if (MyCalculate != null)
                {
                    MyCalculate(this, e);
                }
            }
            public void Calculate(int x, int y)
            {
                CalculateEventArgs e = new CalculateEventArgs(x, y);
                OnCalculate(e);
            }
            public class CalculateEventArgs : EventArgs
            {

                public readonly int x, y;

                public CalculateEventArgs(int x, int y)
                {
                    this.x = x;
                    this.y = y;
                }

            }
        }
        public class CalculatorManager
        {

            public void Add(object sender, Calculator.CalculateEventArgs e)
            {
                Console.WriteLine(e.x + "+" + e.y);
            }
            public void Substract(object sender, Calculator.CalculateEventArgs e)
            {

                Console.WriteLine(e.x + "-" + e.y);
            }


        }

    }
  • 相关阅读:
    Spring
    dispatcher配置
    Filter链执行顺序
    Filter在放行请求前后对response操作导致页面输出差异的剖析
    Javaweb三大组件之Filter
    TensorFlow中loss与val_loss、accuracy和val_accuracy分别是什么含义
    Tomcat启动失败,Failed to destroy end point associated with ProtocolHandler["ajp-nio-8009"] Duplicate unique value [HelloServlet] declared for identity;
    Servlet之创建Servlet基本步骤
    谈谈做oj
    spring实战之获取bean
  • 原文地址:https://www.cnblogs.com/shidengyun/p/5576933.html
Copyright © 2011-2022 走看看