Delegate (dekegate) is a type of dynamic invocation method that is the same as a class, interface, and array, and is a reference type that can be used to implement multicast (MulticastDelegate). Multicast (multicastdelegate): You can use " +" "-" to Merge and remove multiple delegate objects, you can use "+ =" to add a delegate object,"-=" Remove the
Original: http://www.cnblogs.com/zhangchenliang/archive/2012/09/19/2694430.htmlFirst, the beginning of repentanceMy best programming language in C #, I want to say sorry to you, because I have so far understood how delegate and event in C # are used, ashamed of it. Well, today, take advantage of the black and dark night to talk about the simple usage of delegate and event, hoping to bring help to beginners.
For more information about this section, see. NET and C # advanced programming (version 4).
1. Understand Delegation
We know that a callback function is actually a pointer to a method call, that is, a function pointer. In. net, the function pointer concept is implemented in delegate mode .. The main reason for using delegation in. NET is that it is of type security. Why? In the past, for example, in C, the function pointer was just a pointer to a sto
Recently, I spoke to the project team and met some students who have just graduated from school. I claim to be proficient or even proficient in C #. At the beginning, every time I read my resume that says "proficient in C #", I feel an inexplicable excitement. However, the results are often disappointing. After several such experiences, I found that some resumes have too much moisture, and most of them are really skilled, but not C #, but C ++. In other words, what they are "proficient" is the p
Delegates are also called delegates , representing a class of methods. This class of methods has the same modifiers, formal parameters, and return value types .1. The delegate is both a method and a delegate is declared as follows: Add the delegate [' d?l?ɡ?t] keyword after the modifier1 Public Delegate void Del (stri
First, the Commission:The completion of a delegate should be in three steps:STEP01: First define a delegate with delegate;public delegate int Calculatoradd (int x, int y);STEP02: Declares a method to correspond to a delegate.public int Add (int x, int y){return x + y;}protected void Frmtest_load (object sender, EventAr
In the previous blog, we introduced the logic control program of an automated system in the data center. Lambda expressions are used to facilitate the implementation of program functions. however, we should not only strive to implement functions and complete tasks. We should know what it means, that is, knowing Lambda expressions can bring such convenience, we should also know why it brings such convenience. Next, let's take a small journey with you.To find out why, we use Reflector to decompile
A delegate (delegate) is also called an agent, which is a common design pattern in iOS development. We can easily implement this design pattern with the help of Protocol (see Blog: Objective-c Protocol (Protocol)).What is an agent?Apple's official documentation gives a clear explanation:Delegation is a simple and powerful the pattern in which one object in a program acts on behalf of, or in coordination wit
Delegate, Lambda expression, event series 03, from delegate to Lamda expression, lambdalamda
In the article "delegate, Lambda expression, event series 02, and when to use delegate", the use of delegate makes the code much simpler.
namespace ConsoleApplication2{ internal
Delegate, Lambda expression, event series 05, Action delegate and closure, lambdaaction
Here is an example of using the Action delegate:
static void Main(string[] args) { int i = 0; Action a = () => i++; a(); a(); Console.WriteLine(i); }
The result is expected 2. But the curious thing i
Delegate (2): use events to encapsulate delegate variables and
Next article: Delegation (1): Delegation and Methods
We often see this code when studying the design pattern:
It can be said that delegation and events are often used together, and it is quite troublesome. In addition, I think the delegation is quite good. Why should I join the event? It's complicated. OK. Here is a small example to il
Here is an example of using the action delegate:
static void Main(string[] args) { int i = 0; Action a = () => i++; a(); a(); Console.WriteLine(i); }
The result is expected 2. But the curious thing is: how is the variable I on the stack passed to the action delegate?
Check the reverse compilation. First, check the Il code corresp
Sometimes, we want to call a delegate, but we can execute multiple methods at the same time (the most common in custom events), for example, a jobCompositionAfter the file is generated, the system will generate the document log and save it to the database. For the above two operations, if you only want to call one delegate, you can complete it in sequence, you can use multicast delegation.
If you call mul
Question: The difference between delegate and delegateAnalysis:I believe many friends in the development process have encountered the above questions, in order to solve this question, recently consulted a lot of posts, and finally in the official MSDN document found the answer.Here are the official document link addresses for delegate and delegateDelegate: https://msdn.microsoft.com/zh-cn/library/ms173171.a
delegates and events are widely used in the. Net framework, however, a good understanding of delegates and events is not easy for many people who are not in touch with C # for a long time. They are like a sill, after the threshold of the people, it is very easy, and no past people every time to see the Commission and events feel in the heart to panic, uncomfortable. In this article, I'll go through two examples of what is a delegate, why I use delegat
By Lao Zhao (Zhao Yu, Network nameLao Zhao, Foreign nameJeffrey ZhaoHe is currently a researcher at the product development department of Shanda Innovation Institute .)
In his article "feelings about recent interviews", Michael talked about his question about "How to Write delegate in. Net framework1.1, 2.0, and 3.5" during the interview. As a result, a friend replied, "I would like to ask the landlord, but there are several ways to write "and "Contem
Essentially, a delegate is a type-safe object pointing to several methods (similar to a C ++ function pointer ). The maintenance of a delegate has three important information: 1. Address 2 of the method to be called, parameter 3 of the method (if any), and return value of the method (if any ). Unlike C ++ function pointers,. NetThe delegate can point to static me
Event Delegate and js event DelegateLet's first explain what is event delegation:The event Delegate is a child element event, which is delegated to its parent level.Let's take an example:In this example, click li. The current li will change color.It can be seen from the code that the event is bound to the parent level, but clicking each li will change color. This is a typical event Delegate.Event delegation
In the custom delegate implementation, check whether the delegate has implemented the @ protocol method to respond.
In the custom delegate implementation, we will determine whether the delegate is empty. If not, we will call the corresponding delegate function:
Example: if (
Author: Wang Xuan Yi, source: http://www.cnblogs.com/neverdie/Reprinted, Please keep this statement. If you like this article, click [recommendation ]. Thank you!
// This delegate does not pass any parameter public delegate void CallFunc (); // This delegate will pass in the GameObject in which the event occurs, that is, senderpublic
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.