初探.NET中的delegate类型与.NET事件
发布时间:2018-10-08 编辑:jiaochengji.com
教程集为您提供初探.NET中的delegate类型与.NET事件等资源,欢迎您收藏本站,我们将为您提供最新的初探.NET中的delegate类型与.NET事件资源
1.了解delegate
delegate可以认为是一种函数的指针,一个delegate类型的实例代表可以代表一个方法,在实际使用中我们可以在不知道方法名称的情况下调用到这个方法。前面说太多可能会使大家变得糊涂,或者摸不着头脑,我举个例子,来详细说明此种类型的用法:
整个例程的代码,是控制台项目.
//代码开始
using System;
namespace ConsoleApp1
{
public delegate string FunctionPointer(string strName);
class Class1
{
[STAThread]
static void Main(string[] args)
{
//
// TODO: 在此处添加代码以启动应用程序
System.Console.WriteLine("Hello World!");
FunctionPointer fpa = new FunctionPointer(aFunction);
FunctionPointer fpb = new FunctionPointer(bFunction);
InvokeMethod(fpa);
InvokeMethod(fpb);
System.Console.ReadLine();
//
}
public static string aFunction(string sNameA)
{
return "aFunction say i'm " sNameA;
}
public static string bFunction(string sNameB)
{
return "bFunction say i'm " sNameB;
您可能感兴趣的文章:
初探.NET中的delegate类型与.NET事件
C#中的代理(delegate)
学习 asp.net 的事件与委托
C# 事件处理学习心得
ASP.NET2.0泛型和匿名方法介绍
jQuery中bind,live,delegate与one方法的用法及区别解析
ASP.NET 入门的五个步骤
Visual C#资源文件编程--使用资源文件 <zt>-Windows开发-.NET
jquery实现的超出屏幕时把固定层变为定位层的代码
C#的多线程机制探索
[关闭]