This print for content only-size & color not accurate 7" X 9-1/4" / casebound / malloy


// Unbox the reference back into a corresponding short



Download 21,46 Mb.
Pdf ko'rish
bet631/1830
Sana28.09.2021
Hajmi21,46 Mb.
#188411
1   ...   627   628   629   630   631   632   633   634   ...   1830
Bog'liq
[book] [en] Pro C# 2008 and the NET 3.5 Platform Fourth Edition

// Unbox the reference back into a corresponding short.

short anotherShort = (short)objShort;

Again, it is mandatory that you unbox into an appropriate data type. Thus, the following

unboxing logic generates an InvalidCastException exception:



// Illegal unboxing.

static void Main(string[] args)

{

short s = 25;



object objShort = s;

try


{

// The type contained in the box is NOT an int, but a short!

int i = (int)objShort;

}

catch(InvalidCastException e)



{

Console.WriteLine("OOPS!\n{0} ", e.ToString());

}

}

At first glance, boxing/unboxing may seem like a rather uneventful language feature that is



more academic than practical. In reality, the (un)boxing process is very helpful in that it allows us to

assume everything can be treated as a System.Object, while the CLR takes care of the memory-

related details on our behalf.

To see a practical use of this technique, assume you have created a System.Collections.

ArrayList to hold numeric (stack-allocated) data. If you were to examine the members of

ArrayList, you would find they are typically prototyped to receive and return System.Object types:

public class System.Collections.ArrayList : object,

System.Collections.IList,

System.Collections.ICollection,

C H A P T E R   1 0  




Download 21,46 Mb.

Do'stlaringiz bilan baham:
1   ...   627   628   629   630   631   632   633   634   ...   1830




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