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


// This array can only contain types that



Download 21,46 Mb.
Pdf ko'rish
bet564/1830
Sana28.09.2021
Hajmi21,46 Mb.
#188411
1   ...   560   561   562   563   564   565   566   567   ...   1830
Bog'liq
[book] [en] Pro C# 2008 and the NET 3.5 Platform Fourth Edition

// This array can only contain types that

// implement the IPointy interface.

IPointy[] myPointyObjects = {new Hexagon(), new Knife(),

new Triangle(), new Fork(), new PitchFork()};

C H A P T E R   9  



W O R K I N G   W I T H   I N T E R FA C E S



281

8849CH09.qxd  10/1/07  10:41 AM  Page 281




foreach(IPointy i in myPointyObjects)

Console.WriteLine("Object has {0} points.", i.Points);

Console.ReadLine();

}



Source Code

The CustomInterface project is located under the Chapter 9 subdirectory.



Implementing Interfaces Using Visual Studio 2008

Although interface-based programming is a very powerful programming technique, implementing

interfaces may entail a healthy amount of typing. Given that interfaces are a named set of abstract

members, you will be required to type in the definition and implementation for 



each interface

method on 



each type that supports the behavior.

As you would hope, Visual Studio 2008 does support various tools that make the task of imple-

menting interfaces less burdensome. By way of a simple test, insert a final class into your current

project named PointyTestClass. When you implement IPointy (or any interface for that matter) on

a type, you might have noticed that when you complete typing the interface’s name (or when you

position the mouse cursor on the interface name in the code window), the first letter is underlined

(formally termed a “smart tag”). When you click the smart tag, you will be presented a drop-down

list that allows you to implement the interface (see Figure 9-7).



Figure 9-7.

Implementing interfaces using Visual Studio 2008

Notice you are presented with two options, the second of which (explicit interface implemen-

tation) will be examined in the next section. For the time being, once you select the first option, you

will see that Visual Studio 2008 has built generated stub code (within a named code region) for you

to update (note that the default implementation throws a System.Exception, which can obviously

be deleted).

namespace CustomInterface

{

class PointyTestClass : IPointy



{

#region IPointy Members

public byte Points

{

C H A P T E R   9  



W O R K I N G   W I T H   I N T E R FA C E S



282

8849CH09.qxd  10/1/07  10:41 AM  Page 282




get { throw new Exception("The method or operation is not implemented."); }

}

#endregion



}

}


Download 21,46 Mb.

Do'stlaringiz bilan baham:
1   ...   560   561   562   563   564   565   566   567   ...   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