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

推荐订阅源

aimingoo的专栏
aimingoo的专栏
B
Blog RSS Feed
Recent Announcements
Recent Announcements
Vercel News
Vercel News
M
MIT News - Artificial intelligence
阮一峰的网络日志
阮一峰的网络日志
L
LangChain Blog
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
Microsoft Security Blog
Microsoft Security Blog
H
Help Net Security
T
The Blog of Author Tim Ferriss
Y
Y Combinator Blog
G
Google Developers Blog
罗磊的独立博客
爱范儿
爱范儿
宝玉的分享
宝玉的分享
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
酷 壳 – CoolShell
酷 壳 – CoolShell
博客园_首页
S
SegmentFault 最新的问题
WordPress大学
WordPress大学
月光博客
月光博客
人人都是产品经理
人人都是产品经理
Apple Machine Learning Research
Apple Machine Learning Research

博客园 - 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);

        }
    }
}