惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

D
Docker
V
V2EX
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
云风的 BLOG
云风的 BLOG
Blog — PlanetScale
Blog — PlanetScale
Recent Announcements
Recent Announcements
Last Week in AI
Last Week in AI
博客园 - Franky
Microsoft Security Blog
Microsoft Security Blog
Hugging Face - Blog
Hugging Face - Blog
H
Hackread – Cybersecurity News, Data Breaches, AI and More
Vercel News
Vercel News
MyScale Blog
MyScale Blog
大猫的无限游戏
大猫的无限游戏
罗磊的独立博客
H
Help Net Security
月光博客
月光博客
Martin Fowler
Martin Fowler
博客园 - 【当耐特】
宝玉的分享
宝玉的分享
P
Proofpoint News Feed
GbyAI
GbyAI
腾讯CDC
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More

博客园 - beagles

关于QTP 9.2对象库管理的一些总结 “运行错误-不能识别对象”的处理方法(QTP) GetROProperty,GetTOProperties,GetTOProperty的区别 遇到ActiveX无法创建scrīpting.FileSystemObject的问题,我是如何解决的 - beagles - 博客园 QTP中使用描述性编程 在QTP中如何管理对象库 在QTP中如何运用XML管理参数 出师表 酒桌文化 I have a dream - beagles 性能测试经验 一个关于bug度量的公式 (转) Windows性能管理解析(转) 测试术语 开始-运行-命令大全 Web测试总结 测试检查表checklist URL-based 方式和 HTML-based方式的差别(摘自关河) 如何进行安装测试
C#中delegate的典型应用
beagles · 2006-07-11 · via 博客园 - beagles

using System;
using System.Collections.Generic;
using System.Text;

namespace ConsoleApplication7
{
    //下面是用来做为委托函数的参数
    class MathClass
    {
        public static int add(int a, int b)
        {
            return a + b;
        }
        public static int minus(int a,int b)
        {
            return a - b;
 
        }

   
   
    }

    class Handler
    {
        //申明一个委托函数
        private delegate int Calculation(int a, int b);
        //实例化委托函数,这里是一个数组
        private static Calculation[] myCalculation = new Calculation[2];

        public static void EventHandler(int i, int a, int b)
        {
            switch (i)
            {
                case 1:
                    //实例化委托函数,这里是一个数组,把MathClass做为参数传到委托函数中去,MathClass正式委托给myCalculation[0]
                    myCalculation[0] = new Calculation(MathClass.add);
                    myCalculation[1] = new Calculation(MathClass.minus);

                    //在这里,把参数传给myCalculation[0],就像传给MathClass.add一样,因为已经托管
                    Console.WriteLine(myCalculation[0](a,b));
                    Console.WriteLine(myCalculation[1](a, b));
                    break;

                case 2:
                    break;

                default:
                    return;

            }
        }
   
    }
  
   
   
    class Program
    {
        static void Main(string[] args)
        {
            Handler.EventHandler(1,10,3);

        }
    }
}