C#事件与接口
using System; namespace ConsoleApplication1d
{
delegate void MsgDel(string s);
interface IMsg
{
event MsgDel msgd;
void Excute(string s);
} class MInfo : IMsg//必须实现接口的全部成员,如事件,函数
{
//不写这句会提示 Minfo does not implement interface memeber 'IMsg.msgd'
public event MsgDel msgd; //这是对接口中事件的实现!,这里所谓的【实现】比较诡异, 仅仅是重新声明一次
public void Excute(string s) //对接口中Excute的实现
{
if (null != msgd)
msgd(s);
}
}
class Test
{
public static void Main()
{
IMsg msg = new MInfo();
msg.msgd += MSGA;
msg.msgd += MSGB; msg.Excute("hello");
//output
// MSGA: hello
// MSGB: hello
} public static void MSGA(string s)
{
Console.WriteLine("MSGA: " + s);
} public static void MSGB(string s)
{
Console.WriteLine("MSGB: " + s);
}
}
}
C#事件与接口的更多相关文章
- SkylineGlobe 6.6 开放的事件函数接口
SkylineGlobe 6.6 开放的事件函数接口: struct __declspec(uuid("84ce9e1b-65ad-11d5-85c1-0001023952c1") ...
- C#事件与接口编程实例
很多初学c#的朋友对于事件与接口感到迷惑不解,不明白它们之间的关系,下面我就用实例来简单的分析讲解一下. 事件,用event修饰符来代表一个事件,我们要创建一个C#事件必须按以下顺序来扫行: 1,创建 ...
- js:实现自定义事件对象接口
网易2017内推笔试题 要求: 请实现下面的自定义事件Event对象的接口,功能见注释(测试1) 该Event对象的接口需要能被其他对象拓展复用(测试2) //测试1 Event.on('test', ...
- RecyclerView的点击事件添加-------接口回调的形式添加
package com.example.recyclerviewdemo; import android.support.v7.widget.RecyclerView; import android. ...
- 梦想CAD控件事件COM接口知识点
一.鼠标事件 _DMxDrawXEvents::MouseEvent 控件中的鼠标事件. 参数 说明 LONG lType 事件类型,1鼠标移动,2是鼠标左键按下,3是鼠标右键按下,4是鼠标左键双击 ...
- Android开发之自定义组件和接口回调
说到自定义控件不得不提的就是接口回调,在Android开发中接口回调用的还是蛮多的.在这篇博客开始的时候呢,我想聊一下iOS的自定义控件.在iOS中自定义控件的思路是继承自UIView, 在UIVie ...
- Atitit事件代理机制原理 基于css class的事件代理
Atitit事件代理机制原理 基于css class的事件代理 1.1. 在javasript中delegate这个词经常出现,看字面的意思,代理.委托1 1.2. 事件代理1 1.3. 代理标准化规 ...
- 解密jQuery事件核心 - 模拟事件(四)
前几章已经把最核心的实现都分解过了,这一章我们看看jQuery是如何实现事件模拟的 在Internet Explorer 8和更低,一些事件change 和 submit本身不冒泡,但jQuery修改 ...
- .NET 事件
事件概述 在发生其他类或对象关注的事情时,类或对象可通过事件通知它们.发 ...
随机推荐
- Effective Java 34 Emulate extensible enums with interfaces
Advantage Disadvantage Enum types Clarity Safety Ease of maintenance. None extensibility Typesafe en ...
- JavaScript Patterns 2.8 Number Conversions with parseInt()
Strings that start with 0 are treated as octal numbers (base 8) in ECMAScript 3; however, this has c ...
- nodejs创建一个HTTP服务器 简单入门级
const http = require('http');//请求http.createServer(function(request, response){ /*createServer该函数 ...
- PHP递归创建多级目录(一道面试题的解题过程)
今天看到一道面试题,要写出一个可以创建多级目录的函数: 我的第一个感觉就是用递归创建,具体思路如下: function Directory($dir){ if(is_dir($dir) || @mkd ...
- Redis下载及安装部署
官网介绍:Redis is an open source advanced key-value store.It is often referred to as a data structure se ...
- hdu 4856 Tunnels (记忆化搜索)
Tunnels Time Limit: 3000/1500 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Su ...
- php类型转换以及类型转换的判别
部分摘自PHP: 类型 - Manual 相关链接 PHP 在变量定义中不需要(或不支持)明确的类型定义:变量类型是根据使用该变量的上下文所决定的.也就是说,如果把一个 string 值赋给变量 $v ...
- linux command intro2 vi
vi cusor : 0 : to the beginning of the current line $ : to the end of the current line G : to the la ...
- OpenXml入门----给Word文档添加文字
使用OpenXml给word文档添加文字,每个模块都有自己对于的属性以及内容,要设置样式就先声明属性对象,将样式Append到属性里面,再将属性append到模块里面,那么模块里面的内容就具备该样式了 ...
- OpenSSH后门获取root密码及防范
OpenSSH后门获取root密码及防范 相对于Windows操作系统,Linux操作系统的密码较难获取.而很多Linux服务器都配置了Openssh服务,在获取root权限的情况下,可以通过修改或者 ...