Making a delegate
To make a delegate, we're going to write the following above the line that begins with public partial class...
:
public delegate void LabelUpdater();
This is a delegate. It's public
, meaning that it is accessible from anywhere. Notice that it's a keyword--it's blue (Windows) or teal (Mac). Then, void
is a return type and LabelUpdater
is what we named it. This line will basically be used to represent several different functions. So, in our case now, specifically under the Button1_Click
event, we're going to write some code.
As our first step, go outside the set of curly braces under the line that begins with protected void Button1_Click...
and enter the following under closed curly braces:
public void UpdateLabelOne()
You say void
because the methods that are called through the delegates have to have that same void
return type as we have in the declaration of the delegate.
Now, within a set of curly braces below this line, enter the following:
labelOne.Text = $"{DateTime.Now}...