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


// This method allows any object to display the assembly



Download 21,46 Mb.
Pdf ko'rish
bet840/1830
Sana28.09.2021
Hajmi21,46 Mb.
#188411
1   ...   836   837   838   839   840   841   842   843   ...   1830
Bog'liq
[book] [en] Pro C# 2008 and the NET 3.5 Platform Fourth Edition

// This method allows any object to display the assembly

// it is defined in.

public static void DisplayDefiningAssembly(this object obj)

{

Console.WriteLine("{0} lives here:\n\t->{1}\n", obj.GetType().Name,



Assembly.GetAssembly(obj.GetType()));

}

// This method allows any integer to reverse its digits.



// For example, 56 would return 65.

public static int ReverseDigits(this int i)

{

// Translate int into a string, and then



// get all the characters.

char[] digits = i.ToString().ToCharArray();

// Now reverse items in the array.

Array.Reverse(digits);

// Put back into string.

string newDigits = new string(digits);

// Finally, return the modified string back as an int.

return int.Parse(newDigits);

}

}

Again, note how the first parameter of each extension method has been qualified with the this



keyword, before defining the parameter type. It is always the case that the first parameter of an

extension method represents the type being extended. Given that DisplayDefiningAssembly() has

been prototyped to extend System.Object, any type in any assembly now has this new member.

However, ReverseDigits() has been prototyped to only extend integer types, and therefore if any-

thing other than an integer attempts to invoke this method, you will receive a compile-time error.

Understand that a given extension method could have multiple parameters, but 



only the first

parameter can be qualified with this. For example, here is an overloaded extension method defined

in another utility class, named simply TesterUtilClass:

C H A P T E R   1 3  




Download 21,46 Mb.

Do'stlaringiz bilan baham:
1   ...   836   837   838   839   840   841   842   843   ...   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