How to decide between a method or event?

Posted by Wil on Stack Overflow See other posts from Stack Overflow or by Wil
Published on 2011-02-24T07:02:09Z Indexed on 2011/02/24 7:25 UTC
Read the original article Hit count: 130

Filed under:
|
|

I read something ages ago I think by Jon Skeet (which I can't find now) saying that in IL, all events get converted to methods... it was before I understood C# and did not understand it all, but if that is (or even if it isn't) the gist of it....

In a purely hypothetical situation, I was wondering if someone could explain or point me to a resource that says when to use an event over a method?

Basically, If I want to have a big red/green status picture which is linked to a Bool field, and I wanted to change it based on the value of the bool, should I:

a) Have a method called Changepicture which is linked to the field and changes the state of the bool and the picture.

b) Have a get/set part to the field and stick an event in the set part.

c) Have a get/set part to the field and stick a method in the set part.

d) Other?

© Stack Overflow or respective owner

Related posts about c#

Related posts about events