I'm almost done reading John Skeet's book C# In Depth, Third Edition, and I'm surprised that he doesn't use this.property
inside class
es. But since it's John Skeet, I'm sure that means there is a good reason for it.
Example (from pg. 466):
class AsyncForm : Form
{
Label label;
Button button;
public AsyncForm ( )
{
label = new Label { Location = new Point(10, 20),
Text = "Length" };
button = new Button { Location = new Point(10, 50),
Text = "Click" };
button.Click += DisplayWebSiteLength;
Autosize = true;
Controls.Add(label);
Controls.Add(button);
}
// ...
}
No this
on Autosize
and Controls
, eh? Shouldn't we use this
in order to avoid ambiguity as to whether the variable refers to a member of the class or some variable that is global with respect to the class?
I'm wondering because I want to make sure all the code I write is Skeet-certified?