C# 0 The Complete Reference



Download 4,07 Mb.
Pdf ko'rish
bet641/1096
Sana23.01.2022
Hajmi4,07 Mb.
#402171
1   ...   637   638   639   640   641   642   643   644   ...   1096
Bog'liq
C-Sharp 3 The Complete Reference Herbert Schildt

IsWorkNumber

 from within 



PhoneList

. As 


you will see, the compiler won’t let you do it. The reason is that 

IsWorkNumber

 is a property 

defined by 

Friend

, not by 



PhoneNumber

. Thus, 


PhoneList

 has no knowledge of it.



Using an Interface Constraint

The interface constraint enables you to specify an interface that a type argument must 

implement. The interface constraint serves the same two important purposes as the base 

class constraint. First, it lets you use the members of the interface within the generic class. 

Second, it ensures that only type arguments that implement the specified interface are used. 

This means that for any given interface constraint, the type argument must be either the 

interface or a type that implements that interface.

The interface constraint uses this form of the 



where

 clause:


where 

T

:

 interface-name

Here, 

T

 is the name of the type parameter, and 



interface-name

 is the name of the interface. 

More than one interface can be specified by using a comma-separated list. If a constraint 

includes both a base class and interface, then the base class must be listed first.

The following program illustrates the interface constraint by reworking the telephone 

list example shown in the previous section. In this version, the 



PhoneNumber

 class has 

been converted into an interface called 

IPhoneNumber

. This interface is then implemented 

by


Download 4,07 Mb.

Do'stlaringiz bilan baham:
1   ...   637   638   639   640   641   642   643   644   ...   1096




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