分享
 
 
 

13.1 Implicit conversions

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

13.1 Implicit conversions

The following conversions are classified as implicit conversions:

?Identity conversions

?Implicit numeric conversions

?Implicit enumeration conversions.

?Implicit reference conversions

?Boxing conversions

?Implicit constant expression conversions

?User-defined implicit conversions

Implicit conversions can occur in a variety of situations, including

function member invocations (?4.4.3),

cast expressions (?4.6.6), and assignments (?4.13).

The pre-defined implicit conversions always succeed and never cause

exceptions to be thrown. [Note:

Properly designed user-defined implicit conversions should exhibit these

characteristics as well. end note]

13.1.1 Identity conversion

An identity conversion converts from any type to the same type. This

conversion exists only such that an

entity that already has a required type can be said to be convertible to

that type.

13.1.2 Implicit numeric conversions

The implicit numeric conversions are:

?From sbyte to short, int, long, float, double, or decimal.

?From byte to short, ushort, int, uint, long, ulong, float, double, or

decimal.

?From short to int, long, float, double, or decimal.

?From ushort to int, uint, long, ulong, float, double, or decimal.

?From int to long, float, double, or decimal.

?From uint to long, ulong, float, double, or decimal.

?From long to float, double, or decimal.

C# LANGUAGE SPECIFICATION

114

?From ulong to float, double, or decimal.

?From char to ushort, int, uint, long, ulong, float, double, or decimal.

?From float to double.

Conversions from int, uint, long or ulong to float and from long or ulong

to double may cause a

loss of precision, but will never cause a loss of magnitude. The other

implicit numeric conversions never

lose any information.

There are no implicit conversions to the char type, so values of the other

integral types do not automatically

convert to the char type.

13.1.3 Implicit enumeration conversions

An implicit enumeration conversion permits the decimal-integer-literal 0 to

be converted to any enum-type.

13.1.4 Implicit reference conversions

The implicit reference conversions are:

?From any reference-type to object.

?From any class-type S to any class-type T, provided S is derived from T.

?From any class-type S to any interface-type T, provided S implements T.

?From any interface-type S to any interface-type T, provided S is derived

from T.

?From an array-type S with an element type SE to an array-type T with an

element type TE, provided all

of the following are true:

S and T differ only in element type. In other words, S and T have the same

number of dimensions.

Both SE and TE are reference-types.

An implicit reference conversion exists from SE to TE.

?From any array-type to System.Array.

?From any delegate-type to System.Delegate.

?From any array-type or delegate-type to System.ICloneable.

?From the null type to any reference-type.

The implicit reference conversions are those conversions between

reference-types that can be proven to

always succeed, and therefore require no checks at run-time.

Reference conversions, implicit or explicit, never change the referential

identity of the object being

converted. [Note: In other words, while a reference conversion may change

the type of the reference, it never

changes the type or value of the object being referred to. end note]

13.1.5 Boxing conversions

A boxing conversion permits any value-type to be implicitly converted to

the type object or

System.ValueType or to any interface-type implemented by the value-type.

Boxing a value of a valuetype

consists of allocating an object instance and copying the value-type value

into that instance. A struct

can be boxed to the type System.ValueType, since that is a base class for

all structs (?8.3.2).

Boxing conversions are described further in ?1.3.1.

13.1.6 Implicit constant expression conversions

An implicit constant expression conversion permits the following

conversions:

Chapter 13 Conversions

115

?A constant-expression (?4.15) of type int can be converted to type

sbyte, byte, short, ushort,

uint, or ulong, provided the value of the constant-expression is within the

range of the destination

type.

?A constant-expression of type long can be converted to type ulong,

provided the value of the constantexpression

is not negative.

13.1.7 User-defined implicit conversions

A user-defined implicit conversion consists of an optional standard

implicit conversion, followed by

execution of a user-defined implicit conversion operator, followed by

another optional standard implicit

conversion. The exact rules for evaluating user-defined conversions are

described in ?3.4.3.

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