A this-access consists of the reserved word this
.
A this-access is permitted only in the block of a constructor, an instance method, or an instance accessor. It has one of the following meanings:
this
is used in a primary-expression within a constructor of a class, it is classified as a value. The type of the value is the class within which the reference occurs, and the value is a reference to the object being constructed.this
is used in a primary-expression within an instance method or instance accessor of a class, it is classified as a value. The type of the value is the class within which the reference occurs, and the value is a reference to the object for which the method or accessor was invoked.this
is used in a primary-expression within a constructor of a struct, it is classified as a variable. The type of the variable is the struct within which the reference occurs, and the variable represents the struct being constructed. The this
variable of a constructor of a struct behaves exactly the same as an out
parameter of the struct type—this in particular means that the variable must be definitely assigned in every execution path of the constructor.this
is used in a primary-expression within an instance method or instance accessor of a struct, it is classified as a variable. The type of the variable is the struct within which the reference occurs, and the variable represents the struct for which the method or accessor was invoked. The this
variable of an instance method of a struct behaves exactly the same as a ref
parameter of the struct type.Use of this
in a primary-expression in a context other than the ones listed above is an error. In particular, it is not possible to refer to this
in a static method, a static property accessor, or in a variable-initializer of a field declaration.