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



Download 21,46 Mb.
Pdf ko'rish
bet857/1830
Sana28.09.2021
Hajmi21,46 Mb.
#188411
1   ...   853   854   855   856   857   858   859   860   ...   1830
Bog'liq
[book] [en] Pro C# 2008 and the NET 3.5 Platform Fourth Edition

A First Look at Partial Methods

To see the implications of defining a partial method, create a new Console Application project

named PartialMethods. Now, define a new class named CarLocator within a C# file named

CarLocator.cs:

// CarLocator.cs

partial class CarLocator

{

// This member will always be part of the

// CarLocator class.

public bool CarAvailableInZipCode(string zipCode)

{

// This call *may* be part of this method

// implementation.

VerifyDuplicates(zipCode);



// Assume some interesting database logic

// here...

return true;

}

// This member *may* be part of the CarLocator class!

partial void VerifyDuplicates(string make);

}

Notice that the VerifyDuplicates() method has been defined with the partial modifier and



does not define a method body within this file. Also notice that the CarAvailableInZipCode()

method is making a call to VerifyDuplicates() within its implementation.

If you were to compile this application as it now stands and open the compiled assembly 

into a tool such as ildasm.exe or reflector.exe, you will find no trace of the VerifyDuplicates()

method in the CarLocator class, and no trace of the call to VerifyDuplicates() within

CarAvailableInZipCode()! Given the project as it now stands, you really authored the following

definition of the CarLocator class as far as the compiler is concerned:

internal class CarLocator

{

public bool CarAvailableInZipCode(string zipCode)



{

return true;

}

}

The reason for this strange stripping away of code has to do with the fact that our partial



VerifyDuplicates() method was never given a true implementation. If we were to now add a new

file to our project (named perhaps CarLocatorImpl.cs) that defined the remainder of our partial

method:

// CarLocatorImpl.cs

partial class CarLocator

{

partial void VerifyDuplicates(string make)



{

// Assume some expensive data validation

C H A P T E R   1 3  


Download 21,46 Mb.

Do'stlaringiz bilan baham:
1   ...   853   854   855   856   857   858   859   860   ...   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