Raising and handling events
Methods are often described as actions that an object can do. For example, a List
class can add an item to itself or clear itself.
Events are often described as actions that happen to an object. For example, in a user interface, a Button
has a Click
event, click being something that happens to a button.
Another way of thinking of events is a way of exchanging messages between two objects.
Calling methods using delegates
You have already seen the most common way to call or execute a method: use the "dot" syntax to access the method using its name.
The other way to call or execute a method is to use a delegate. If you have used languages that support function pointers, then you can think of a delegate as being a type-safe ...
Get C# 6 and .NET Core 1.0: Modern Cross-Platform Development now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.