Can anyone place some clear examples of using Events in C# (or any .NET language)?
There are plenty of such on the internet, but most of them are complicated and they don’t apply to every situation. Make it universal if possible please.
Can anyone place some clear examples of using Events in C# (or any .NET
Share
Events are the basis of event-driven programming (obviously). So an event is appropriate any time you want to take action(s) based on something else occuring. What that something else could be a myriad of things – a user clicking a button, a timer elapsing, a window being closed, etc. It’s hard to make it really universal, since there are so many different scenarios.
One example would be to fill a label with text when the user clicks on a button:
Note that SetTextLabel is a function that you would provide, and it should be ThreadSafe (otherwise I would get pounded by commenters saying my code wasn’t so.)