C# 0 The Complete Reference


The Reference Type and Value Type Constraints



Download 4,07 Mb.
Pdf ko'rish
bet647/1096
Sana23.01.2022
Hajmi4,07 Mb.
#402171
1   ...   643   644   645   646   647   648   649   650   ...   1096
Bog'liq
C-Sharp 3 The Complete Reference Herbert Schildt

The Reference Type and Value Type Constraints

The next two constraints enable you to indicate that a type argument must be either a 

reference type or a value type. These are useful in the few cases in which the difference 

between reference and value types are important to generic code. Here is the general form 

of the reference type constraint:

where 


T

 : class


In this form of the 

where

 clause, the keyword 



class

 specifies that 



T

 must be a reference type. 

Thus, an attempt to use a value type, such as 

int

 or 


bool

, for 


T

 will result in a compilation 

error.

Here is the general form of the value type constraint:



where 

T

 : struct

In this case, the keyword 

struct

 specifies that 



T

 must be a value type. (Recall that structures 

are value types.) Thus, an attempt to use a reference type, such as 

string

, for 


T

 will result in 

a compilation error. In both cases, when additional constraints are present


Download 4,07 Mb.

Do'stlaringiz bilan baham:
1   ...   643   644   645   646   647   648   649   650   ...   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