|
|
The current object - this | The latest receiver of a message is called the current object.
This is the object on which the latest instance method has been called.
|
The current object in a C# program execution is denoted by the variable this |
This example shows two different uses of this. First, it may be necessary
to get access to the current object as such. In the example it is necessary
to add the current account to a list of accounts. The second use pertain
to methods (and constructors). It is convenient to use the same name for both formal
parameters of methods and instance variables of the surrounding class. To disambiguate
these, this.x refers to the instance variable named x, and x refers to
the local meaning of x. |
In this example, any use of a member of the current object is prefixed with this.
This is a more radical use of this, which highlights use of members in the current object
in contrast to members in other objects.
|
|
Read more about the current object in the text book version of this material. |