C# Language Specification


User-defined implicit conversions



Download 0,75 Mb.
bet160/524
Sana06.01.2022
Hajmi0,75 Mb.
#324842
1   ...   156   157   158   159   160   161   162   163   ...   524
Bog'liq
CSharp Language Specification

User-defined implicit conversions


A user-defined implicit conversion from type S to type T is processed as follows:

  • Determine the types S0 and T0. If S or T are nullable types, S0 and T0 are their underlying types, otherwise S0 and T0 are equal to S and T respectively.

  • Find the set of types, D, from which user-defined conversion operators will be considered. This set consists of S0 (if S0 is a class or struct), the base classes of S0 (if S0 is a class), and T0 (if T0 is a class or struct).

  • Find the set of applicable user-defined and lifted conversion operators, U. This set consists of the user-defined and lifted implicit conversion operators declared by the classes or structs in D that convert from a type encompassing S to a type encompassed by T. If U is empty, the conversion is undefined and a compile-time error occurs.

  • Find the most specific source type, SX, of the operators in U:

  • If any of the operators in U convert from S, then SX is S.

  • Otherwise, SX is the most encompassed type in the combined set of source types of the operators in U. If exactly one most encompassed type cannot be found, then the conversion is ambiguous and a compile-time error occurs.

  • Find the most specific target type, TX, of the operators in U:

  • If any of the operators in U convert to T, then TX is T.

  • Otherwise, TX is the most encompassing type in the combined set of target types of the operators in U. If exactly one most encompassing type cannot be found, then the conversion is ambiguous and a compile-time error occurs.

  • Find the most specific conversion operator:

  • If U contains exactly one user-defined conversion operator that converts from SX to TX, then this is the most specific conversion operator.

  • Otherwise, if U contains exactly one lifted conversion operator that converts from SX to TX, then this is the most specific conversion operator.

  • Otherwise, the conversion is ambiguous and a compile-time error occurs.

  • Finally, apply the conversion:

  • If S is not SX, then a standard implicit conversion from S to SX is performed.

  • The most specific conversion operator is invoked to convert from SX to TX.

  • If TX is not T, then a standard implicit conversion from TX to T is performed.

      1. Download 0,75 Mb.

        Do'stlaringiz bilan baham:
1   ...   156   157   158   159   160   161   162   163   ...   524




Ma'lumotlar bazasi mualliflik huquqi bilan himoyalangan ©hozir.org 2024
ma'muriyatiga murojaat qiling

kiriting | ro'yxatdan o'tish
    Bosh sahifa
юртда тантана
Боғда битган
Бугун юртда
Эшитганлар жилманглар
Эшитмадим деманглар
битган бодомлар
Yangiariq tumani
qitish marakazi
Raqamli texnologiyalar
ilishida muhokamadan
tasdiqqa tavsiya
tavsiya etilgan
iqtisodiyot kafedrasi
steiermarkischen landesregierung
asarlaringizni yuboring
o'zingizning asarlaringizni
Iltimos faqat
faqat o'zingizning
steierm rkischen
landesregierung fachabteilung
rkischen landesregierung
hamshira loyihasi
loyihasi mavsum
faolyatining oqibatlari
asosiy adabiyotlar
fakulteti ahborot
ahborot havfsizligi
havfsizligi kafedrasi
fanidan bo’yicha
fakulteti iqtisodiyot
boshqaruv fakulteti
chiqarishda boshqaruv
ishlab chiqarishda
iqtisodiyot fakultet
multiservis tarmoqlari
fanidan asosiy
Uzbek fanidan
mavzulari potok
asosidagi multiservis
'aliyyil a'ziym
billahil 'aliyyil
illaa billahil
quvvata illaa
falah' deganida
Kompyuter savodxonligi
bo’yicha mustaqil
'alal falah'
Hayya 'alal
'alas soloh
Hayya 'alas
mavsum boyicha


yuklab olish