分享
 
 
 

14.4 Function members

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

Function members are members that contain executable statements. Function

members are always members

of types and cannot be members of namespaces. C# defines the following

categories of function members:

?Methods

?Properties

?Events

?Indexers

?User-defined operators

?Instance constructors

?Static constructors

?Destructors

Except for static constructors and destructors (which cannot be invoked

explicitly), the statements contained

in function members are executed through function member invocations. The

actual syntax for writing a

function member invocation depends on the particular function member

category.

The argument list (?4.4.1) of a function member invocation provides actual

values or variable references

for the parameters of the function member.

Invocations of methods, indexers, operators, and instance constructors

employ overload resolution to

determine which of a candidate set of function members to invoke. This

process is described in ?4.4.2.

Once a particular function member has been identified at compile-time,

possibly through overload

resolution, the actual run-time process of invoking the function member is

described in ?4.4.3.

[Note: The following table summarizes the processing that takes place in

constructs involving the six

categories of function members that can be explicitly invoked. In the

table, e, x, y, and value indicate

expressions classified as variables or values, T indicates an expression

classified as a type, F is the simple

name of a method, and P is the simple name of a property.

Construct Example Description

-------------------------------------------------------------------------

Method F(x, y) Overload resolution is applied to select

invocation the best method F in the containing class

or struct. The method is invoked with the

argument list (x, y). If the method is not

static, the instance expression is this.

-------------------------------------------------------------------------

T.F(x, y) Overload resolution is applied to select

the best method F in the class or struct

T. A compile-time error occurs if the

method is not static. The method is invoked

with the argument list (x, y).

-------------------------------------------------------------------------

e.F(x, y) Overload resolution is applied to select the

best method F in the class, struct, or

interface given by the type of e. A

compile-time error occurs if the method is

static. The method is invoked with the

instance expression e and the argument

list (x, y).

-------------------------------------------------------------------------

Property P The get accessor of the property P in the

access containing class or struct is invoked. A

compile-time error occurs if P is writeonly.

If P is not static, the instance expression

is this.

-------------------------------------------------------------------------

P = value The set accessor of the property P in the

containing class or struct is invoked with

the argument list (value). A compiletime

error occurs if P is read-only. If P is not

static, the instance expression is this.

-------------------------------------------------------------------------

T.P The get accessor of the property P in the

class or struct T is invoked. A compile-time

error occurs if P is not static or if P is

write-only.

-------------------------------------------------------------------------

T.P = value The set accessor of the property P in the

class or struct T is invoked with the

argument list (value). A compile-time error

occurs if P is not static or if P is

read-only.

-------------------------------------------------------------------------

e.P The get accessor of the property P in the

class, struct, or interface given by the

type of e is invoked with the instance

expression e. A compile-time error occurs

if P is static or if P is write-only.

--------------------------------------------------------------------------

e.P = value The set accessor of the property P in the

class, struct, or interface given by the

type of e is invoked with the instance

expression e and the argument list (value).

A compile-time error occurs if P is static

or if P is read-only.

--------------------------------------------------------------------------

Event access E += value The add accessor of the event E in the

containing class or struct is invoked. If

E is not static, the instance expression

is this.

-------------------------------------------------------------------------

E -= value The remove accessor of the event E in the

containing class or struct is invoked. If

E is not static, the instance expression

is this.

------------------------------------------------------------------------

T.E += value The add accessor of the event E in the

class or struct T is invoked. A

compile-time error occurs if E is not

static.

------------------------------------------------------------------------

T.E -= value The remove accessor of the event E in the

class or struct T is invoked. A

compile-time error occurs if E is not

static.

------------------------------------------------------------------------

e.E += value The add accessor of the event E in the

class, struct, or interface given by the

type of e is invoked with the instance

expression e. A compile-time error occurs

if E is static.

------------------------------------------------------------------------

e.E -= value The remove accessor of the event E in the

class, struct, or interface given by the

type of e is invoked with the instance

expression e. A compile-time error occurs

if E is static.

------------------------------------------------------------------------

Indexer e[x, y] Overload resolution is applied to select

access the best indexer in the class, struct, or

interface given by the type of e. The get

accessor of the indexer is invoked with the

instance expression e and the argument list

(x, y). A compile-time error occurs if the

indexer is write-only.

------------------------------------------------------------------------

e[x, y] = value Overload resolution is applied to select

the best indexer in the class, struct, or

interface given by the type of e. The set

accessor of the indexer is invoked with

the instance expression e and the argument

list (x, y, value). A compile-time error

occurs if the indexer is read-only.

------------------------------------------------------------------------

Operator -x Overload resolution is applied to select

invocation the best unary operator in the class or

struct given by the type of x. The

selected operator is invoked with the

argument list (x).

------------------------------------------------------------------------

x + y Overload resolution is applied to select

the best binary operator in the classes

or structs given by the types of x and y.

The selected operator is invoked with the

argument list (x, y).

------------------------------------------------------------------------

Instance new T(x, y) Overload resolution is applied to select

constructor the best instance constructor in the class

invocation or struct T. The instance constructor is

invoked with the argument list (x, y).

 
 
 
免责声明:本文为网络用户发布,其观点仅代表作者个人观点,与本站无关,本站仅提供信息存储服务。文中陈述内容未经本站证实,其真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
2023年上半年GDP全球前十五强
 百态   2023-10-24
美众议院议长启动对拜登的弹劾调查
 百态   2023-09-13
上海、济南、武汉等多地出现不明坠落物
 探索   2023-09-06
印度或要将国名改为“巴拉特”
 百态   2023-09-06
男子为女友送行,买票不登机被捕
 百态   2023-08-20
手机地震预警功能怎么开?
 干货   2023-08-06
女子4年卖2套房花700多万做美容:不但没变美脸,面部还出现变形
 百态   2023-08-04
住户一楼被水淹 还冲来8头猪
 百态   2023-07-31
女子体内爬出大量瓜子状活虫
 百态   2023-07-25
地球连续35年收到神秘规律性信号,网友:不要回答!
 探索   2023-07-21
全球镓价格本周大涨27%
 探索   2023-07-09
钱都流向了那些不缺钱的人,苦都留给了能吃苦的人
 探索   2023-07-02
倩女手游刀客魅者强控制(强混乱强眩晕强睡眠)和对应控制抗性的关系
 百态   2020-08-20
美国5月9日最新疫情:美国确诊人数突破131万
 百态   2020-05-09
荷兰政府宣布将集体辞职
 干货   2020-04-30
倩女幽魂手游师徒任务情义春秋猜成语答案逍遥观:鹏程万里
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案神机营:射石饮羽
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案昆仑山:拔刀相助
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案天工阁:鬼斧神工
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案丝路古道:单枪匹马
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:与虎谋皮
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:李代桃僵
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:指鹿为马
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案金陵:小鸟依人
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案金陵:千金买邻
 干货   2019-11-12
 
推荐阅读
 
 
 
>>返回首頁<<
 
靜靜地坐在廢墟上,四周的荒凉一望無際,忽然覺得,淒涼也很美
© 2005- 王朝網路 版權所有