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 Service即四大组件总结

    原文转载自:http://www.cnblogs.com/bravestarrhu/archive/2012/05/02/2479461.html Service 服务: 一个Service 是一段长 ...

  2. liunx环境下安装mysql数据库

    一:如果你的机器上之前安装有mysql数据库,先进行卸载 (1)需要先将它的文件删除 (2)同时注意删除老板本的etc/my.cnf文件和/etc/mysql目录,这两个文件控制的是mysql的一些配 ...

  3. Entity Framework Code First级联删除

    如果我们要到一对主从表增加级联删除,则要在主表中的引用属性上增加Required关键字,如: public class Destination { public int DestinationId { ...

  4. Maven使用教程

    一.Maven介绍 我们在开发项目的过程中,会使用一些开源框架.第三方的工具等等,这些都是以jar包的方式被项目所引用,并且有些jar包还会依赖其他的jar包,我们同样需要添加到项目中,所有这些相关的 ...

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

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

  6. linu、C语言、计算机基础教程

    Linux操作系统入门教程:http://see.xidian.edu.cn/cpp/linux/ 鸟哥的linux私房菜:http://vbird.dic.ksu.edu.tw/ 计算机操作系统教程 ...

  7. uvalive 3135 Argus priority_queue

    用优先队列维护每个时间点优先级最高的元素. #include<iostream> #include<cstdio> #include<cstdlib> #inclu ...

  8. uva 11020 Efficient Solutions

    题意:给你n个人,有两个属性x.y,如果不存在另外一个人x2,y2满足 x2<=x,y2<y 或者 x2<x,y2<=y,那么就称这个人是有优势的,每次给你一个人得信息,问你当 ...

  9. 《GettingThingsDone》--GTD学习笔记(三)-GTD的三个关键原则

    原则一:养成收集的习惯 1.收集习惯给个人带来的好处     在收集过程中你会出现焦虑和解脱,难以招架和控制良好的情绪. (1)消极情绪的来源     要做的事情总比你能做的事情多,要做的事情太多并不 ...

  10. leetcode@ [322] Coin Change (Dynamic Programming)

    https://leetcode.com/problems/coin-change/ You are given coins of different denominations and a tota ...