14.5.7 This access

王朝other·作者佚名  2006-02-28
窄屏简体版  字體: |||超大  

A this-access consists of the reserved word this.

this-access:

this

A this-access is permitted only in the block of an instance constructor, an

instance method, or an instance

accessor. It has one of the following meanings:

?When this is used in a primary-expression within an instance constructor

of a class, it is classified as a

value. The type of the value is the class within which the usage occurs,

and the value is a reference to the

object being constructed.

Chapter 14 Expressions

145

?When 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 usage occurs, and the value is

a reference to the object for which the method or accessor was invoked.

?When this is used in a primary-expression within an instance constructor

of a struct, it is classified as a

variable. The type of the variable is the struct within which the usage

occurs, and the variable represents

the struct being constructed. The this variable of an instance constructor

of a struct behaves exactly the

same as an out parameter of the struct type?in particular, this means that

the variable must be

definitely assigned in every execution path of the instance constructor.

?When 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 usage 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 a compile-time error. In

particular, it is not possible to refer to this in a static method, a

static property accessor, or in a variableinitializer

of a field declaration.

 
 
 
免责声明:本文为网络用户发布,其观点仅代表作者个人观点,与本站无关,本站仅提供信息存储服务。文中陈述内容未经本站证实,其真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
 
 
© 2005- 王朝網路 版權所有 導航