A class that is defined with the "sealed" keyword cannot be inherited. So if I define a class as follows:
sealed class A
{
public int DATA;
}
This would fail to compile because class A is "sealed" and cannot be derived:
class B : A
{
}
The "this" reserved word returns a reference to the object in the current context. Look at the following example:
sealed class A
{
public int DATA = 25;
public int Add100()
{
// These two lines are equivalent
this.DATA = this.DATA + 50;
DATA = DATA + 50;
return DATA;
}
public A ReturnMe()
{
return this;
}
}
In the above example "this" returns the current object and it is of the type A. You will notice two equivalent lines. this.DATA and DATA point to the same thing. You will also notice in the ReturnMe method the object returns a reference of itself. This is not practical but you normally use the "this" reserved word to pass a reference of yourself to another object.
You could see it like this:
public void btnLaunch_Click(…)
{
frmDialog dlgEdit = new frmDialog();
dlgEdit.Tag = this;
dlgEdit.ShowDialog(this);
}
In the example there I create a dialog and pass a reference of the current dialog to the Tag property on the new dialog. That way frmDialog can modify members on the class that loaded it.
2 responses so far