`
yaoyuan
  • 浏览: 26266 次
最近访客 更多访客>>
社区版块
存档分类
最新评论

Delegates, Events, and Lambdas

    博客分类:
  • .Net
阅读更多

1. Specifically speaking, a delegate object maintains three important pieces of information:

• The address of the method on which it makes calls
• The arguments (if any) of this method
• The return value (if any) of this method

 

2. When the C# compiler processes delegate types, it automatically generates a sealed class deriving from System.MulticastDelegate. This class (in conjunction with its base class, System.Delegate) provides the necessary infrastructure for the delegate to hold onto a list of methods to be invoked at a later time.

 

3. C# delegate definition results in a sealed class with three compiler-generated methods whose parameter and return types are based on the delegate’s declaration. The following pseudo-code approximates the basic pattern:

// This is only pseudo-code! 	 
public sealed class DelegateName : System.MulticastDelegate 	 
{ 	 
	public DelegateName (object target, uint functionAddress); 	 
	public delegateReturnValue Invoke(allDelegateInputRefAndOutParams); 	 
	public IAsyncResult BeginInvoke(allDelegateInputRefAndOutParams, 	 
	AsyncCallback cb, object state); 	 
	public delegateReturnValue EndInvoke(allDelegateRefAndOutParams, 	 
	IAsyncResult result); 	 
} 	 
 
 
分享到:
评论

相关推荐

    Delegates-and-Events-in-CSharp

    3. **匿名方法与lambda表达式**: 在C# 3.0及以后版本,可以通过匿名方法或lambda表达式创建没有名字的函数,这使得在委托使用中更加灵活。 4. **委托实例化与调用**: 使用`new DelegateType()`来实例化委托,并使用...

    Learn-Events-Delegates-And-Lambdas:来自 PluralSight C# 事件、委托和 Lambda

    Learn-Events-Delegates-And-Lambdas 来自 PluralSight C# 事件、委托和 Lambda 模块 1 - 事件、委托和事件处理程序 事件 - 发送给订阅者的通知 (Button_Click) 鼠标按下触发点击事件。 多个对象可以通过订阅事件...

    AW - Essential C# 4.0, 3rd Edition Mar 2010+完美版

    Delegates, events, and lambda expressions Collection interfaces and standard query operators Query expressions and the tree expressions on which LINQ providers are based Reflection, attributes, and...

    Pro C# 7: With .NET and .NET Core

    Chapter 10: Delegates, Events, and Lambda Expressions Chapter 11: Advanced C# Language Features Chapter 12: LINQ to Objects Chapter 13: Understanding Object Lifetime Part V: Programming with .NET ...

    Csharp.6.0.and.the.NET.4.6.Framework.7th.Edition.1484213335.epub

    Chapter 10: Delegates, Events, and Lambda Expressions Chapter 11: Advanced C# Language Features Chapter 12: LINQ to Objects Chapter 13: Understanding Object Lifetime Part V: Programming with .NET ...

    Essential C# 4.0 (第三版)

    Delegates, events, and lambda expressions Collection interfaces and standard query operators Query expressions and the tree expressions on which LINQ providers are based Reflection, attributes, and...

    Delegates-and-Events-in-CSharp.rar_C#编程_PPT_

    3. **实例化委托**:我们可以使用方法名或者Lambda表达式实例化委托,将其绑定到具体的方法。 ```csharp MyDelegate myDel = new MyDelegate(WriteMessage); MyDelegate myDel2 = (msg) => Console.WriteLine(msg...

    Essential C# 5.0-Englis

    effective exception handling into your code* Using generics, delegates, Lambda expressions, and events to reduce code complexity* Learning dynamic programming with reflection and attributes* Querying...

    Packt.Mastering.Csharp.and.NET.Programming

    - **True Reason for Delegates**: Explains why delegates were introduced in C#, primarily for event handling and functional programming. - **The Evolution in Versions 2.0 and 3.0**: - **Generics**: ...

    C#4.0新特性源码

    5. **改进的委托和事件(Improved Delegates and Events)**:引入了`Func<T>`和`Action<T>`等预定义委托,简化了无状态、匿名函数的使用。此外,`+=`和`-=`运算符可以直接用于事件订阅和取消订阅。 6. **改进的...

    委托和事件详解,全面掌握委托和事件

    现在,关于提供的PDF文件,"Delegates-and-Events-in-CSharp.pdf"和"Delegates-and-Events-in-CSharp-Continued.pdf"很可能是深入教程,涵盖了委托和事件的更多细节,包括如何声明、实例化、多播委托,以及如何在类...

    Interactive C# Fundamentals, Core Concepts and Patterns的例子源码

    8. **委托与事件(Delegates and Events)**:C#中的委托是类型安全的函数指针,常用于事件处理。源码可能会展示如何使用委托和事件进行回调和通信。 9. **属性(Properties)**:C#的属性提供了一种封装数据的方式...

    Beginning Microsoft Visual CSharp 2008 Wiley Publishing(english)

    Using the LINQ Method Syntax and Lambda Expressions 892 Ordering Query Results 895 orderby Clause 897 Ordering Using Method Syntax 897 Querying a Large Data Set 899 Aggregate ...

    Pro c# and .NET framework

    2. 委托(delegates)、事件(events)和lambda表达式(lambda expressions)之间的关系:讲解了.NET中用于回调函数和事件处理的委托,以及如何使用事件驱动编程。同时,介绍了lambda表达式和它们在简化委托使用中的...

    (Wrox Professional C# 2012 and .NET 4.5.pdf

    委托、lambda表达式和事件(Delegates, Lambdas, and Events): 解释了委托的使用,lambda表达式的简写语法以及事件驱动编程的基础。 字符串和正则表达式(Strings and Regular Expressions): 涉及在C#中处理文本...

    微软.NET程序员高级培训教程系列资料.C#(下)【英文版】

    "CSharp_Module 12_Operators Delegates and Events.pdf"会讲解如何使用这些运算符,以及如何重载运算符以满足特定需求。 5. **委托(Delegates)**:委托是C#中的一种类型,它引用一个或多个方法。它们在事件处理、...

    C_threads_events_delegate_instance.rar_delegate_threads_线程委托

    在C#编程中,线程(threads)、事件(events)和委托(delegates)是构建多线程应用程序和实现异步编程的关键概念。本压缩包文件"ydaima"可能包含一些示例代码或教程,旨在帮助理解这些概念在实际应用中的工作方式。...

    CLR via C# 3rd Edition

    Added discussion of events and thread-safety as well as showing a cool extension method to simplify the raising of an event. Chapter 12-Generics 新增讨论了委托和接口泛型类型参数的不同。 Chapter 13...

Global site tag (gtag.js) - Google Analytics