C#委托实例
using
System;
using
System.Collections.Generic;
using
System.Linq;
using
System.Text;
namespace
weituo
{
class
Program
{
static
void
Main(
string
[] args)
{
// 声明委托变量
ProcessDelegate process;
Console.WriteLine(
"请输入用逗号分隔的两个数字:"
);
string
input = Console.ReadLine();
int
commaPos = input.IndexOf(
','
);
double
param1 = Convert.ToDouble(input.Substring(0, commaPos));
double
param2 = Convert.ToDouble(input.Substring(commaPos + 1,input.Length - commaPos -1));
Console.WriteLine(
"输入M乘法D除法"
);
input =Console.ReadLine();
// 初始化委托变量
if
(input ==
"M"
)
process =
new
ProcessDelegate(Multiply);
//注释:此处也可以写process = Multiply
else
process =
new
ProcessDelegate(Divide);
// 使用委托调用函数
double
result = process(param1,param2);
Console.WriteLine(
"结果:{0}"
,result);
Console.ReadKey();
}
// 声明委托
delegate
double
ProcessDelegate(
double
param1,
double
param2);
static
double
Multiply(
double
param1,
double
param2)
{
return
param1 * param2;
}
static
double
Divide(
double
param1,
double
param2)
{
return
param1 / param2;
}
}
}
C#委托实例的更多相关文章
- C#创建委托实例
using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace MyDe ...
- C# 委托实例(跨窗体操作控件)
在C#里面却是可以不用自定义消息这么复杂的方法来实现跨窗体调用控件,C#有更好的办法就是委托. 效果描述:有两个窗体,FORM1(一个名为“打开form2”的button控件)和FORM2(一个名为“ ...
- 【C#】回调方法不通过object参数获得委托实例
回调方法中几乎都会存在获取委托实例的需求,进而通过委托实例调用EndInvoke以得到异步执行的返回值.在我看过的相关文章中,获取委托实例的方法几乎都是同一个,就是向BeginInvoke的最后一个参 ...
- C# 委托实例实现的多种类型
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.T ...
- Asp.Net 利用反射获得委托和事件以及创建委托实例和添加事件处理程序
子程序定义: public delegate void CurrentControlListenEvent(string uniqueID, string way = null); public ev ...
- jQuery的事件委托实例分析
事件委托主要是利用事件冒泡现象来实现的,对于事件委托的精准的掌握,可以有利于提高代码的执行效率.先看一段代码实例: <!DOCTYPE html> <html> <hea ...
- [C#]委托实例分析(附源码)
一直都听说C#中的委托与事件非常重要,都没有什么切身的体会,而这次通过做一个WinForm二次开发的项目才真正感觉到了委托与事件的犀利之处. 1.C#中的事件和委托的作用? 事件代表一个组件能够被关注 ...
- jQuery事件绑定和委托实例
本文实例讲述了jQuery事件绑定和委托.分享给大家供大家参考.具体方法如下: jQuery事件的绑定和委托可以用多种方法实现,on() . bind() . live() . delegate ...
- C#中委托和事件的区别实例解析
这篇文章主要介绍了C#中委托和事件的区别,并分别以实例形式展示了通过委托执行方法与通过事件执行方法,以及相关的执行流程与原理分析,需要的朋友可以参考下 本文实例分析了C#中委托和事件的区别,分享给大家 ...
随机推荐
- MongoDB常用操作总结
====================================MGDB的操作====================================== 0.创建数据库时使用(use 数据库 ...
- C# 时间与时间戳互转 13位
/// <summary> /// 将c# DateTime时间格式转换为Unix时间戳格式 /// </summary> /// <param name="t ...
- graphviz - Node Shapes
Node Shapes There are three main types of shapes : polygon-based, record-based and user-defined. The ...
- 【C++】虚函数
I 动态绑定.多态.虚函数.对象的静态类型与动态类型 1.基类中有两种函数: 派生类直接继承不做改变 派生类重新定义成适合自身的版本覆盖掉基类的函数 对于第一种就是普通的基类成员函数,第二种通常通过将 ...
- sqlserver 在脚本中,为所有字符前没有N标记的字符增加N
{[^N]}{'[\u4e00-\u9fa5]|[\u4e00-\U9fa5]|[0-9]|[A-Z]} \1N\2
- golang json string remove field
golang中如何移除多余的field? 同样是json结构,不能像js 的json一样 delete key 直接移除,网上找了很多相似的,还没找到解决办法,先mark一下 感谢大神提供解决思路,设 ...
- ubuntu12.04 登录黑屏
新安装的ubuntu12.04LTS,登录之后黑屏,切换到ubuntu2D能够进入UI.解决方法记录于此. 转载: http://blog.csdn.net/albertsh/article/deta ...
- Apple Developer Program Roles Overview
Apple Developer Program Roles Overview There are three roles that can be assigned to Apple Developer ...
- CentOS设置虚拟网卡做NAT方式和Bridge方式桥接
CentOS设置虚拟网卡做NAT方式和Bridge方式桥接 http://www.centoscn.com/CentOS/config/2015/0225/4736.html 摘要:KVM虚拟机网络配 ...
- python判断类型
方法 isinstance(obj, type) 示例 >>> print isinstance(, int) True >>> print isinstance( ...