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);
            }


        }

    }
  • 相关阅读:
    route-over VS mesh-under
    IOS算法(三)之插入排序
    GitHub学习笔记
    Python-面向对象 (二 继承)
    POJ 3518 Prime Gap(素数题)
    struts2的总体回想(ACTION、拦截器、值栈、OGNL表达式、ModelDriven方案等)
    first move advantage_百度搜索
    【绿茶书情】:《SOHO小报》和《凤…
    潘石屹的SOHO小报猝死
    ASP.NET Hashtable输出JSON格式数据
  • 原文地址:https://www.cnblogs.com/shidengyun/p/5576933.html
Copyright © 2011-2022 走看看