-
Book Overview & Buying
-
Table Of Contents
-
Feedback & Rating

C# 6 and .NET Core 1.0

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.
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 method pointer. In other words, a delegate is just the memory address of a method that matches the same signature as the delegate.
For example, imagine there is a method that must have a string
passed as its only parameter and it returns an int
:
public...
Change the font size
Change margin width
Change background colour