C#的委托(delegate)和事件(event)

有一些概念是看过一次记得,久不接触就忘了的,但是以后要重新捡起,又要花些时间看书,所以记下来为了巩固。

1. 申明Deleagate:其实背后是IL编译器为你创造了一个封装函数指针的类,这个类名就是你申明时所用的函数名,例如Delegate void AddDelegate(int, int)。winForm技术中喜欢将AddDelegate称为AddEventHandler,所以也就有了那么多EventHandler。

2. 申明Event::当Event和前面申明的委托,也就是AddEventHandler联合申明一个事件,例如 public event AddEventHandler addevent, 这个IL编译出来的的是包含函数指针列表的类实例。而addevent()调用,就变成函数列表的调用,官方文字称诸多订阅该事件的委托实例的调用。所以订阅的语句:addevent+= new AddEventHandler(clientDimAdd) ,也就是将这个回调函数加入到列表中,以便事件触发时依次调用。

12,143人评论了“C#的委托(delegate)和事件(event)”

  1. I have to show some thanks to the writer for rescuing me from this circumstance. After looking throughout the world-wide-web and coming across thoughts that were not helpful, I was thinking my life was done. Existing without the answers to the problems you’ve fixed by means of your short post is a critical case, as well as the kind that could have in a negative way affected my entire career if I had not discovered your web page. Your own personal natural talent and kindness in touching all areas was valuable. I am not sure what I would’ve done if I hadn’t discovered such a solution like this. I can at this point look forward to my future. Thanks a lot so much for your skilled and amazing guide. I won’t be reluctant to propose your web blog to anybody who ought to have guide on this matter.

  2. Hello, i think that i saw you visited my site thus
    i came to “return the favor”.I’m attempting to
    find things to improve my web site!I suppose its ok to use a few of your ideas!!

  3. I am really loving the theme/design of your blog. Do you
    ever run into any browser compatibility problems? A handful of my blog visitors have
    complained about my site not working correctly in Explorer but looks great
    in Firefox. Do you have any tips to help fix this problem?

  4. I’m really enjoying the design and layout of your site.
    It’s a very easy on the eyes which makes it much more enjoyable for me to
    come here and visit more often. Did you hire out a designer to create your theme?
    Excellent work!

  5. Definitely imagine that which you stated. Your favorite reason appeared to be at the internet the easiest thing to be aware of.
    I say to you, I certainly get irked while other people consider issues that they
    plainly do not recognise about. You controlled to
    hit the nail upon the top and outlined out the entire thing with no need side effect ,
    people can take a signal. Will probably be again to
    get more. Thank you

  6. I do not even understand how I stopped up right here, however
    I assumed this post used to be good. I do not know who you are however certainly you’re going to
    a well-known blogger in case you are not already.
    Cheers!

  7. hey there and thank you for your information – I’ve certainly picked up anything new from right
    here. I did however expertise a few technical points using
    this site, as I experienced to reload the site a lot
    of times previous to I could get it to load properly.
    I had been wondering if your web hosting is OK?
    Not that I’m complaining, but slow loading
    instances times will very frequently affect your placement in google and can damage your high quality score if advertising and marketing with Adwords.
    Well I am adding this RSS to my e-mail and can look out for much more of your
    respective interesting content. Ensure that you update this again soon.

  8. Do you mind if I quote a few of your posts
    as long as I provide credit and sources back to your
    webpage? My blog site is in the exact same niche as yours and my users would definitely benefit from a lot of the information you present here.

    Please let me know if this okay with you. Thank you!

  9. Heya i am for the first time here. I came across this board and I find It
    really useful & it helped me out a lot. I’m hoping to present one thing back and help
    others such as you aided me.

  10. Good day! I know this is kind of off topic but I was wondering if you knew where I could find a captcha
    plugin for my comment form? I’m using the same blog platform as yours and I’m having difficulty finding one?
    Thanks a lot!

  11. You really make it seem so easy with your presentation but I find this topic to be actually something that I
    think I would never understand. It seems too complex and extremely broad for me.

    I’m looking forward for your next post, I will try to get the hang of it!

  12. An impressive share, I just given this onto a colleague who was doing just a little evaluation on this. And he in fact bought me breakfast as a result of I discovered it for him.. smile. So let me reword that: Thnx for the treat! However yeah Thnkx for spending the time to debate this, I really feel strongly about it and love studying more on this topic. If potential, as you become experience, would you mind updating your blog with more particulars? It is extremely useful for me. Massive thumb up for this blog put up!

  13. Simply a smiling visitor here to share the love (:, btw great design and style. “Make the most of your regrets… . To regret deeply is to live afresh.” by Henry David Thoreau.

  14. Howdy I am so thrilled I found your blog page, I really found
    you by mistake, while I was researching on Google for something
    else, Nonetheless I am here now and would just like to say thanks for a tremendous post
    and a all round exciting blog (I also love the theme/design), I don’t have time to look
    over it all at the minute but I have book-marked it and also added your RSS feeds, so when I have time I will be back to
    read more, Please do keep up the excellent work.

  15. Hello! Someone in my Facebook group shared this website with us so I came to
    take a look. I’m definitely enjoying the information.
    I’m book-marking and will be tweeting this to my followers!
    Fantastic blog and excellent design and style.

  16. This design is incredible! You definitely know how to keep
    a reader amused. Between your wit and your videos, I was almost moved
    to start my own blog (well, almost…HaHa!) Fantastic job.
    I really loved what you had to say, and more than that, how
    you presented it. Too cool!

  17. Hello I am so happy I found your blog, I really found you by mistake, while I was searching on Bing for something else,
    Regardless I am here now and would just like to say thank you for a remarkable post and a all
    round entertaining blog (I also love the theme/design), I don’t
    have time to go through it all at the moment but I have bookmarked it and also included your RSS feeds, so
    when I have time I will be back to read a great deal more, Please do keep up
    the great job.

  18. I know this if off topic but I’m looking into
    starting my own weblog and was wondering what all is needed to get setup?

    I’m assuming having a blog like yours would cost a pretty penny?

    I’m not very internet smart so I’m not 100% certain. Any
    suggestions or advice would be greatly appreciated. Thank you

  19. Attractive section of content. I just stumbled upon your site and in accession capital to assert that I get actually enjoyed account your blog posts. Anyway I’ll be subscribing to your augment and even I achievement you access consistently fast.

  20. Howdy, I do think your web site could be having web
    browser compatibility problems. Whenever I take a look
    at your site in Safari, it looks fine however when opening in I.E.,
    it’s got some overlapping issues. I just wanted to give you a quick heads up!
    Besides that, great blog!

  21. Hello there, I found your web site by way of Google at the same time as searching
    for a similar topic, your web site got here up, it appears to be
    like good. I’ve bookmarked it in my google bookmarks.
    Hi there, just turned into aware of your weblog thru Google, and
    found that it’s truly informative. I am going to be careful
    for brussels. I’ll appreciate if you happen to proceed this
    in future. Lots of other folks will likely be benefited out of your writing.

    Cheers!

  22. Great post however , I was wanting to know if you could write a litte more on this subject?
    I’d be very grateful if you could elaborate a little bit further.
    Bless you!

  23. Woah! I’m really loving the template/theme of this website.
    It’s simple, yet effective. A lot of times it’s
    challenging to get that “perfect balance” between user friendliness and visual appeal.
    I must say you’ve done a superb job with this. In addition, the blog
    loads extremely fast for me on Chrome. Outstanding Blog!

  24. We’re a group of volunteers and starting a new scheme in our community.
    Your web site provided us with valuable info to
    work on. You’ve done an impressive job and our entire community will be thankful
    to you.

发表评论

电子邮件地址不会被公开。 必填项已用*标注