why do we do this:
private string StatusText
{
set { toolStripStatusLabel1.Text = value; }
}
instead of just this?
private string StatusText
{
toolStripStatusLabel1.Text = value;
}
i do not understand the point of using set?
These are two completely different things.
This is a method:
private string StatusText()
{
toolStripStatusLabel1.Text = value;
}
which is called like this:
StatusText();
(and which will not compile, because the local variable value
cannot be found). To make it work, you would need to write it like this:
private string StatusText(string value)
{
toolStripStatusLabel1.Text = value;
}
and call it like this:
StatusText("bla");
On the other hand, this is the definition of a property:
private string StatusText
{
set { toolStripStatusLabel1.Text = value; }
}
whose setter (hence the keyword set
) is called like this:
StatusText = "bla";
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With