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. Ext入门学习系列(二)弹出窗体

    第二章 弹出窗体 上节学习了Ext的环境搭建和最基本的一个操作——弹出对话框,作为一个引子,本节讲述如何弹出一个新窗体,从实例讲解Ext的基本运行原理. 一.Ext的窗体长什么样? 先来看看几个效果, ...

  2. [转载]C#基础-Func,Action

    Func,Action 的介绍及其用法 Func是一种委托,这是在3.5里面新增的,2.0里面我们使用委托是用Delegate,Func位于System.Core命名空间下,使用委托可以提升效率,例如 ...

  3. uboot里读sd卡内容

    1. sd卡升级命令 mmcinit 0 fatload mmc 0:1 0 uzImage.bin 80000 fatload mmc 0:1 1000000 initrd.gz 580000 bo ...

  4. 设计模式之Memento(备忘机制)

    Memento备望录模式定义:memento是一个保存另外一个对象内部状态拷贝的对象.这样以后就可以将该对象恢复到原先保存的状态. Memento模式相对也比较好理解,我们看下列代码: public ...

  5. Python脚本控制的WebDriver 常用操作 <二十二> 处理alert / confirm / prompt

    测试用例场景 webdriver中处理原生的js alert confirm 以及prompt是很简单的.具体思路是使用switch_to.alert()方法定位到alert/confirm/prom ...

  6. 【译】 AWK教程指南 附录C-AWK的内建函数

    C.1 字串函数 index( 原字串, 查找的子字串 ) 若原字串中含有欲寻找的子字串,则返回该子字串在原字串中第一次出现的位置,若未曾出现该子字串则返回0. 例如: $ awk 'BEGIN{ p ...

  7. dateline 在数据库中就是 整型字段。date函数是可以转换成可读日期的。

    返回数据中的dateline全部用date()函数转换后再返回,是要嵌套循环还是遍历,代码怎么写? //查询我的活动 function user_activity_info_by_uid($uid){ ...

  8. ·string和date转化以及数据库时间比较

    string 转换成dateString date="2014-06-26 10:09:22.819": SimpleDateFormat sdf = new SimpleDate ...

  9. HW7.11

    import java.util.Scanner; public class Solution { public static void main(String[] args) { Scanner i ...

  10. hdu 5585 Numbers【大数+同余定理】

    Numbers Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total Sub ...