Delegate and events in. Net (suitable for beginners and will definitely understand a lot after reading)

Source: Internet
Author: User

In fact, at the beginning, I was a little confused about the incident and delegation. I went to find some information and expected to see a good article, which benefited a lot.

The following is an imitation click event I wrote after reading it.

1 public class button
2 {
3 Public string name = "I Am a button ";
4 Public Delegate void clickeventhandler (Object sender, clickeventargs E );
5 public event clickeventhandler click;
6 public class clickeventargs: eventargs
7 {
8 Public readonly string name;
9 Public clickeventargs (string name)
10 {
11 This. Name = Name;
12}
13}
14 public virtual void onclick (clickeventargs E)
15 {
16 if (Click! = NULL)
17 {
18 click (this, e );
19}
20}
21 public void danji ()
22 {
23 clickeventargs E = new clickeventargs (name );
24 onclick (E );
25}
26
27}
28 public class task
29 {
30 public void onclick (Object sender, button. clickeventargs E)
31 {
32 console. writeline (E. Name );
33}
34}
35 class clickevent
36 {
37 static void main (string [] ARGs)
38 {
39 button BTN = new button ();
40 BTN. Click + = (new task (). onclick;
41 BTN. danji ();
42}
43}

 

That article is very well written. I will not introduce it. I will give you a URL. You can check it out.

Http://www.cnblogs.com/JimmyZhang/archive/2007/09/23/903360.html

Contact Us

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.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.