using System;
using System.Collections.Generic;
using System.Linq;
using System.Text; namespace Delegate
{
public delegate void Task(); class Program
{ static void Main(string[] args)
{
Task[] task = { MethodA, MethodB, MethodC};
string resp;
do
{ Console.WriteLine("Task-A");
Console.WriteLine("Task-B");
Console.WriteLine("Task-C");
Console.WriteLine("X exit");
resp = Console.ReadLine();
if (resp.ToUpper() == "X")
{
break;
}
try
{
int choice = int.Parse(resp) - 1;
task[choice]();
}
catch {
Console.WriteLine("Invalid number");
}
} while (true); Console.ReadLine(); } public static void MethodA() {
Console.WriteLine("A doing");
}
public static void MethodB()
{
Console.WriteLine("B doing");
}
public static void MethodC()
{
Console.WriteLine("C doing");
}
}
}

C#_delegate - example的更多相关文章

  1. Swift开发教程--关于Existing instance variable '_delegate'...的解决的方法

    xcode编译提示问题:Existing instance variable '_delegate' for property 'delegate' with  assign attribute mu ...

  2. C#_delegate - 异步调用实例 BeginInvoke EndInvoke event

    using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.T ...

  3. C#_delegate - 有返回值手工调用

    using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.T ...

  4. C#_delegate - 用委托实现事件,Display和Log类都使用Clock对象

    //public event SecondChangeHandler OnSecondChange; 若将委托加上event,则视作是事件,不是委托,外围就不能直接对OnSecondChange传值 ...

  5. C#_delegate - Pair<T> 静态绑定

    using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.T ...

  6. C#_delegate - Pair<T> & 简单顺序逆序 & 方法委托(在Pair类下)&枚举类型 混搭使用

    using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.T ...

  7. C#_delegate和事件 - 如果金额小于0则触发事件

    using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.T ...

  8. C#_delegate EndInvoke

    using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.T ...

  9. C#_delegate - 调用列表 计算阶乘

    using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace Dele ...

  10. C#_delegate - 值参数和引用参数

    值参数不能加,引用参数可以. 引用参数是共享的 using System; using System.Collections.Generic; using System.Linq; using Sys ...

随机推荐

  1. 【转】Android动态改变对 onCreateDialog话框值 -- 不错不错!!!

    原文网址:http://www.111cn.net/sj/android/46484.htm 使用方法是这样的,Activity.showDialog()激发Activity.onCreateDial ...

  2. (二)学习CSS之cursor属性

    参考:http://www.w3school.com.cn/tiy/t.asp?f=csse_zindex cursor 属性规定要显示的光标的类型(形状). <html> <bod ...

  3. Hibernate4.x之Session--常用方法

    接上篇文章继续学习Hibernate的Session(http://www.cnblogs.com/dreamfree/p/4111777.html) 持久化对象的状态; 站在持久化的角度,Hiber ...

  4. GIS:揭开你神秘的面纱

    转自:http://www.cnblogs.com/gisangela/archive/2013/02/20/2918884.html#!comments GIS从出现到为人所知,只不过经历了短短的几 ...

  5. 【Tcpcopy】离线回放功能

    最近因调试问题,需要一直进行tcpcopy,拿有问题的包进行测试.决定使用tcpcopy对录制脚本进行回放,以下为我操作的具体步骤.主要是三块 1 下载安装具有离线回放功能的tcpcopy 2 使用t ...

  6. HDU 1074 Doing Homework 状压DP

    由于数据量较小,直接二进制模拟全排列过程,进行DP,思路由kuangbin blog得到,膜拜斌神 #include<iostream> #include<cstdio> #i ...

  7. Android_1_渐变背景色

    首先创建一个渐变背景色文件drawable-mdpi/bg_color.xml <?xml version="1.0" encoding="utf-8"? ...

  8. oracle修改process和session数

    第一步:连接服务器,输入sqlplus 第二步:以sysdba身份登陆 第三步:查看和修改processes和sessions参数 1. 查看processes和sessions参数 select * ...

  9. Magento 前台的logo更改

    进入后台: 系统-配置, 然后选择左栏的“设计”, 选择右栏的“页眉”里面, 一般logo的路径在: skin/frontend/base/default/images/media/logo.png ...

  10. 题解西电OJ (Problem 1007 -做一名正气的西电人 )--长整型计算

    Description 一天,wm和zyf想比比谁比较正气,但正气这种东西无法量化难以比较,为此,他们想出了一个方法,两人各写一个数字,然后转化为二进制,谁的数字中二进制1多谁就比较正气! Input ...