C# Language Specification


Uniqueness of implemented interfaces



Download 0,75 Mb.
bet448/524
Sana06.01.2022
Hajmi0,75 Mb.
#324842
1   ...   444   445   446   447   448   449   450   451   ...   524
Bog'liq
CSharp Language Specification

Uniqueness of implemented interfaces


The interfaces implemented by a generic type declaration must remain unique for all possible constructed types. Without this rule, it would be impossible to determine the correct method to call for certain constructed types. For example, suppose a generic class declaration were permitted to be written as follows:

interface I


{
void F();
}

class X: I, I // Error: I and I conflict


{
void I.F() {...}
void I.F() {...}
}

Were this permitted, it would be impossible to determine which code to execute in the following case:

I x = new X();
x.F();

To determine if the interface list of a generic type declaration is valid, the following steps are performed:



  • Let L be the list of interfaces directly specified in a generic class, struct, or interface declaration C.

  • Add to L any base interfaces of the interfaces already in L.

  • Remove any duplicates from L.

  • If any possible constructed type created from C would, after type arguments are substituted into L, cause two interfaces in L to be identical, then the declaration of C is invalid. Constraint declarations are not considered when determining all possible constructed types.

In the class declaration X above, the interface list L consists of I and I. The declaration is invalid because any constructed type with U and V being the same type would cause these two interfaces to be identical types.

It is possible for interfaces specified at different inheritance levels to unify:

interface I
{
void F();
}

class Base: I


{
void I.F() {…}
}

class Derived: Base, I // Ok


{
void I.F() {…}
}

This code is valid even though Derived implements both I and I. The code

I x = new Derived();
x.F();

invokes the method in Derived, since Derived effectively re-implements I (§13.4.6).



      1. Download 0,75 Mb.

        Do'stlaringiz bilan baham:
1   ...   444   445   446   447   448   449   450   451   ...   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