c# - Why to use events somewhere where method is enough? -
i read events tutorial , not benefit in simple code this..method should used same way:
class bulb { public delegate void handler(); public event handler glowing; ... glowing+=somemethod; private void turnon { glowing(); } private void somemethod { } }
simply events allow others using code perform custom implementation want when event occurs (when bulb glowing).
simply calling method won't tell anybody has happened.
events basic element of event driven programming
if program doesn't need tell event don't need implement such functionality. having such functionality has benefits.
for example when using list
class dont know when item got added (if @ point other code that) in observablecollection
notifications when items added or removed.
an event message sent object signal occurrence of action. action caused user interaction, such mouse click, or triggered other program logic.
Comments
Post a Comment