How do static events compare to non-static events in C#?

后端 未结 5 672
误落风尘
误落风尘 2020-12-31 05:47

I just realized static events exist - and I\'m curious how people use them. I wonder how the relative comparison holds up to static vs. instance methods. For instance, a s

5条回答
  •  天涯浪人
    2020-12-31 06:34

    for some insight check this link http://www.codeproject.com/KB/cs/staticevent.aspx

    static event can be used

    • when no instance exists
    • to do some multicast event for all existing instances...
    • when you have a static class which can fire events...

    BUT one should use them with cuation... see discussion http://groups.google.com/group/microsoft.public.dotnet.languages.csharp/browse_thread/thread/2ac862f346b24a15/8420fbd9294ab12a%238420fbd9294ab12a?sa=X&oi=groupsr&start=1&num=2

    more info

    http://msdn.microsoft.com/en-us/library/8627sbea.aspx
    http://dylanbeattie.blogspot.com/2008/05/firing-static-events-from-instance.html
    http://www.nivisec.com/2008/09/static-events-dont-release.html

提交回复
热议问题