C # delegate introduction (delegate, Action, Func, predicate ),A delegate is a class that defines the type of a method so that the method can be passed as a parameter of another method. An event is a special delegate.
1. Delegate
onclick.Speaking of the onclick, you have to say the event events in. Net.event handling in C # is actually a delegate with a special signature, like this:public delegate void MyEventHandler (object sender, MyEventArgs e);Of the two parameters, sender represents the event sender, and E is the event argument class. The MyEventArgs class is used to contain event-r
the delegate object or its carrying method (methods)
Declare delegate type
The declaration of a delegate type is generally composed of four parts: (a) access level; (B) keyword delegate; (c) return type, and the declaration form (Signature) of the method carried by the
story behind the onclick.Speaking of the onclick, you have to say the event events in. Net.event handling in C # is actually a delegate with a special signature, like this:public delegate void MyEventHandler (object sender, MyEventArgs e);Of the two parameters, sender represents the event sender, and E is the event argument class. The MyEventArgs class is used t
I've been optimizing a WinForm form application to show how to lower the module's low coupling through "delegates" and "events."
But before that, we have to understand what a low coupling is.
The simple thing is that two modules, if a class in a module, you need to instantiate a class in another module, and then call the method so that the two modules are tied to a chariot, and if a module disappears suddenly, an error is made, and all we have to do is add the method in a module to a
. Ondelegate-= this. ondelegate; } (2). If the method of emptying the delegate is not declared in the class, we can use Getinvocationlist to query the delegate reference and then remove it.Here's how: static void Main (string[] args) {program test = new program (); if (test. Ondelegate = null) {
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
Bind method to delegate
Through the example of (1), is there a dream? So, are you wondering: In the above example, I don't have to assign a value to the name parameter directly in the greetpeople () method. I can use the variable like this:
Static void main (string [] ARGs ){String name1, name2;Name1 ="Jimmy";Name2 ="Half smoke";
Greetpeople (name1, english
Speaking of delegates, some people who are just getting started in C # feel very tall and have no contact, but in fact a lot of people have used lambda expression, in fact, lambda expression is a delegate.About the introduction of a delegate there's a great God written in detail: Zhang Ziyang's blog in C # for delegates and events-Part.1. Follow Simin's understan
PanPen120 on CSDN original, such as other sites reproduced please pay attention to the layout and the source:Research commissioned, because there is the basis of function pointers, but also easy to get started, but for some concepts and practices, always to make it very clear and tangled, these several commissioned articles I was combined with the "C # and. NET4 Advanced Program Design", MSDN, draw on other people's blog summary discourse, With the mo
C # commissioned the basic series was originally published in February 2011 in my Sina blog, now it will be like this blog.
Multi-Channel delegation
Class Program {public delegate void Saythingtos (string s);
void SayHello (String s) {Console.WriteLine ("Hello {0}", s);
} void Saygoodbye (String s) {Console.WriteLine ("Goodbye {0}", s);
} static void Main (string[] args) {//mode
C # uses the BeginInvoke and EndInvoke methods of the delegate (Delegate) to manipulate threadsC # 2011-03-05 13:06:24 read 19 Comments 0 font Size: Big Small SubscriptionManipulating threads with the BeginInvoke and EndInvoke methods of the delegate (Delegate)There are many
A delegate is a data structure that refers to a group of multiple methods, to instance methods, and to the object instances that correspond to those methods.Delegate IntroductionA delegate is a type of reference method. Once a delegate has been assigned a method, the delegate will have exactly the same behavior as the
This article mainly introduces the use of javascript Delegate blur and focus. The example analyzes the usage of javascript Delegate and the usage skills for common browsers, for more information about how to use the javascript Delegate blur and focus, see the example in this
Example Analysis of the Use of javascript Delegate (Delegate) blur and focus, delegateblur
This article describes how to use the javascript Delegate blur and focus. Share it with you for your reference. The specific analysis is as follows:
Opera (9.5b) cannot correctly trigger all focus and blur events twice;Therefore,
This example describes the JavaScript delegate (Delegate) Blur and focus usage. Share to everyone for your reference. The specific analysis is as follows:
Opera (9.5b) for all focus and blur events, can not be correctly triggered two times;Therefore, the processing functions of the focus and blur events can be delegated to the capture phase of the event.
Objective
Previous C # using attribute to implement AOP transactions [C # | AOP | Attribute | ContextAttribute | Icontributeobjectsink | IMessageSink] is a way to achieve or to achieve an AOP effect, in fact, the earliest design in C # using AOP to complete the transaction plan is to use delegate, but not accustomed t
A delegate is a type that holds a reference to a method in an object and is also a type-safe function pointer. Give you an example://declares a delegate, where NewDelegate () is understood to be a type that is then used to fetch the method. Delegate voidnewdelegate ();//The following is a two-way definition of a, B, w
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.