7.4.2.3 Better conversion
Visual Studio .NET 2003
Given an implicit conversion C1 that converts from a type S to a type T1, and an implicit conversion C2 that converts from a type S to a type T2, the better conversion of the two conversions is determined as follows:
- If
T1andT2are the same type, neither conversion is better. - If
SisT1,C1is the better conversion. - If
SisT2,C2is the better conversion. - If an implicit conversion from
T1toT2exists, and no implicit conversion fromT2toT1exists,C1is the better conversion. - If an implicit conversion from
T2toT1exists, and no implicit conversion fromT1toT2exists,C2is the better conversion. - If
T1issbyteandT2isbyte,ushort,uint, orulong,C1is the better conversion. - If
T2issbyteandT1isbyte,ushort,uint, orulong,C2is the better conversion. - If
T1isshortandT2isushort,uint, orulong,C1is the better conversion. - If
T2isshortandT1isushort,uint, orulong,C2is the better conversion. - If
T1isintandT2isuint, orulong,C1is the better conversion. - If
T2isintandT1isuint, orulong,C2is the better conversion. - If
T1islongandT2isulong,C1is the better conversion. - If
T2islongandT1isulong,C2is the better conversion. - Otherwise, neither conversion is better.
If an implicit conversion C1 is defined by these rules to be a better conversion than an implicit conversion C2, then it is also the case that C2 is a worse conversion than C1.