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



Download 21,46 Mb.
Pdf ko'rish
bet612/1830
Sana28.09.2021
Hajmi21,46 Mb.
#188411
1   ...   608   609   610   611   612   613   614   615   ...   1830
Bog'liq
[book] [en] Pro C# 2008 and the NET 3.5 Platform Fourth Edition

// Detach other sink from events.

Console.WriteLine("\n***** Removing second sink *****");

c1.Unadvise(myOtherSink);

Console.ReadLine();

}

Callback interfaces can be helpful in that they can be used under any language or platform



(.NET, J2EE, or otherwise) that supports interface-based programming. However, as mentioned,

Chapter 11 will examine a number of event-centric techniques that are specific to the .NET

platform. 



Source Code

The CallbackInterface project is located under the Chapter 9 subdirectory.



Summary

An interface can be defined as a named collection of abstract members. Because an interface does

not provide any implementation details, it is common to regard an interface as a behavior that may

be supported by a given type. When two or more classes implement the same interface, you are able

to treat each type the same way (aka interface-based polymorphism) even if the types are defined

within unique class hierarchies.

C# provides the interface keyword to allow you to define a new interface. As you have seen, a

type can support as many interfaces as necessary using a comma-delimited list. Furthermore, it is

permissible to build interfaces that derive from multiple base interfaces.

In addition to building your custom interfaces, the .NET libraries define a number of standard

(i.e., framework-supplied) interfaces. As you have seen, you are free to build custom types that

implement these predefined interfaces to gain a number of desirable traits such as cloning, sorting,

and enumerating. Finally, you spent some time investigating how interface types can be used to

establish bidirectional communications between two objects in memory.

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



308

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




Collections and Generics

T

he most primitive container within the .NET platform is the System.Array type. As you have seen

over the course of the previous chapters, C# arrays allow you to define a set of identically typed

items (including an array of System.Objects, which essentially represents an array of any types) of

a fixed upper limit. While this will often fit the bill, there are many other times where you require

more flexible data structures, such as a dynamically growing and shrinking container, or a container

that can hold only items that meet a specific criteria (e.g., only items deriving from a given base

class, items implementing a particular interface, or whatnot). To begin understanding the task of

building flexible and type-safe containers, this chapter will first examine the System.Collections

namespace that has been part of the .NET base class libraries since the initial release.

However, since the release of .NET 2.0, the C# programming language was enhanced to sup-

port a new feature of the CTS termed 



generics. Many of the generics you will use on a daily basis are

found within the System.Collections.Generic namespace. As shown over this chapter, generic con-

tainers are in many ways far superior to their nongeneric counterparts in that they provide greater

type safety and performance benefits. Once you’ve seen generic support within the base class

libraries, in the remainder of this chapter you’ll examine how you can build your own generic

members, classes, structures, and interfaces.




Download 21,46 Mb.

Do'stlaringiz bilan baham:
1   ...   608   609   610   611   612   613   614   615   ...   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