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



Download 21,46 Mb.
Pdf ko'rish
bet756/1830
Sana28.09.2021
Hajmi21,46 Mb.
#188411
1   ...   752   753   754   755   756   757   758   759   ...   1830
Bog'liq
[book] [en] Pro C# 2008 and the NET 3.5 Platform Fourth Edition

Understanding Indexer Methods

As programmers, we are very familiar with the process of accessing individual items contained

within a standard array using the index operator ([]), for example:

static void Main(string[] args)

{

// Loop over incoming start up params.

for(int i = 0; i < args.Length; i++)

Console.WriteLine("Args: {0}", args[i]);

// Declare an array of local integers.

int[] myInts = { 10, 9, 100, 432, 9874};



// Use the [] operator to access each element.

for(int j = 0; j < myInts.Length; j++)

Console.WriteLine("Index {0}  = {1} ", j,  myInts[j]);

Console.ReadLine();

}

The previous code is by no means a major newsflash. However, the C# language provides the



capability to design custom classes and structures that may be indexed just like a standard array, by

defining an indexer method. This particular language feature is most useful when you are creating

custom collection types (generic or nongeneric).

Before examining how to create such a construct, let’s begin by seeing one in action. Assume

you have added support for an indexer method to the custom PeopleCollection type developed in

Chapter 10 (specifically, the CustomNonGenericCollection project). Observe the following usage

within a new Console Application named SimpleIndexer:

383

C H A P T E R   1 2

8849CH12.qxd  9/26/07  11:31 AM  Page 383




Download 21,46 Mb.

Do'stlaringiz bilan baham:
1   ...   752   753   754   755   756   757   758   759   ...   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