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


// Converting a System.Int32 to a Square



Download 21,46 Mb.
Pdf ko'rish
bet790/1830
Sana28.09.2021
Hajmi21,46 Mb.
#188411
1   ...   786   787   788   789   790   791   792   793   ...   1830
Bog'liq
[book] [en] Pro C# 2008 and the NET 3.5 Platform Fourth Edition

// Converting a System.Int32 to a Square.

Square sq2 = (Square)90;

Console.WriteLine("sq2 = {0}", sq2);

// Converting a Square to a System.Int32.

int side = (int)sq2;

Console.WriteLine("Side length of sq2 = {0}", side);

Console.ReadLine();

}

and here is the update to the Square type:



public struct Square

{

...



public static explicit operator Square(int sideLength)

{

Square newSq;



newSq.Length = sideLength;

return newSq;

}

public static explicit operator int (Square s)



{return s.Length;}

}

To be honest, converting from a Square into a System.Int32 may not be the most intuitive (or



useful) operation. However, this does point out a very important fact regarding custom conversion

routines: the compiler does not care what you convert to or from, as long as you have written syn-

tactically correct code. Thus, as with overloading operators, just because you can create an explicit

cast operation for a given type does not mean you should. Typically, this technique will be most

helpful when you’re creating .NET structure types, given that they are unable to participate in

classical inheritance (where casting comes for free).




Download 21,46 Mb.

Do'stlaringiz bilan baham:
1   ...   786   787   788   789   790   791   792   793   ...   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