Custom event on variable change
-
i am not too familiar with events in .net I am wishing make my program fire an event when a variable changes, how can I do that? thx
2hdass wrote:
I am wishing make my program fire an event when a variable changes, how can I do that?
You can't. If the variable is a field on the class then you should encapsulate it in a property and have the property's setter fire the event. This article[^] shows how to use events (See the sibling to sibling section). The event is fired from a method, but a property is just syntactic sugar for a get or set method anyway.
Upcoming events: * Glasgow: Mock Objects, SQL Server CLR Integration, Reporting Services, db4o, Dependency Injection with Spring ... "I wouldn't say boo to a goose. I'm not a coward, I just realise that it would be largely pointless." My website
-
2hdass wrote:
I am wishing make my program fire an event when a variable changes, how can I do that?
You can't. If the variable is a field on the class then you should encapsulate it in a property and have the property's setter fire the event. This article[^] shows how to use events (See the sibling to sibling section). The event is fired from a method, but a property is just syntactic sugar for a get or set method anyway.
Upcoming events: * Glasgow: Mock Objects, SQL Server CLR Integration, Reporting Services, db4o, Dependency Injection with Spring ... "I wouldn't say boo to a goose. I'm not a coward, I just realise that it would be largely pointless." My website