Table of Contents 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 Notes DownloadECMA334 C# Language Specification 13 Conversions 13.4 Userdefined conversions 13.4.4 Userdefined explicit conversions
Paragraph 11 A userdefined explicit conversion from type S to type T is processed as follows:  2 Find the set of types, D, from which userdefined conversion operators will be considered. 3 This set consists of S (if S is a class or struct), the base classes of S (if S is a class), T (if T is a class or struct), and the base classes of T (if T is a class).
 4 Find the set of applicable userdefined conversion operators, U. 5 This set consists of the userdefined implicit or explicit conversion operators declared by the classes or structs in D that convert from a type encompassing or encompassed by S to a type encompassing or encompassed by T. 6 If U is empty, the conversion is undefined and a compiletime error occurs.
 7 Find the most specific source type, SX, of the operators in U:
 8 If any of the operators in U convert from S, then SX is S.
 9 Otherwise, if any of the operators in U convert from types that encompass S, then SX is the most encompassed type in the combined set of source types of those operators. 10 If no most encompassed type can be found, then the conversion is ambiguous and a compiletime error occurs.
 11 Otherwise, SX is the most encompassing type in the combined set of source types of the operators in U. 12 If no most encompassing type can be found, then the conversion is ambiguous and a compiletime error occurs.
 13 Find the most specific target type, TX, of the operators in U:
 14 If any of the operators in U convert to T, then TX is T.
 15 Otherwise, if any of the operators in U convert to types that are encompassed by T, then TX is the most encompassing type in the combined set of target types of those operators. 16 If no most encompassing type can be found, then the conversion is ambiguous and a compiletime error occurs.
 17 Otherwise, TX is the most encompassed type in the combined set of target types of the operators in U. 18 If no most encompassed type can be found, then the conversion is ambiguous and a compiletime error occurs.
 19 If U contains exactly one userdefined conversion operator that converts from SX to TX, then this is the most specific conversion operator. 20 If no such operator exists, or if more than one such operator exists, then the conversion is ambiguous and a compiletime error occurs. 21 Otherwise, the userdefined conversion is applied:
 22 If S is not SX, then a standard explicit conversion from S to SX is performed.
 23 The most specific userdefined conversion operator is invoked to convert from SX to TX.
 24 If TX is not T, then a standard explicit conversion from TX to T is performed.

Jagger Software Ltd 
Company # 4070126 
VAT # 762 5213 42 