C# 0 The Complete Reference


[ ]  operator. It is possible to define the  [ ]



Download 4,07 Mb.
Pdf ko'rish
bet327/1096
Sana23.01.2022
Hajmi4,07 Mb.
#402171
1   ...   323   324   325   326   327   328   329   330   ...   1096
Bog'liq
C-Sharp 3 The Complete Reference Herbert Schildt

[ ]

 operator. It is possible to define the 



[ ]

 operator for classes that you create, but you don’t use an 



operator

 method. Instead, you 

create an 

indexer.

 An indexer allows an object to be indexed like an array. The main use of 

indexers is to support the creation of specialized arrays that are subject to one or more 

constraints. However, you can use an indexer for any purpose for which an array-like 

syntax is beneficial. Indexers can have one or more dimensions. We will begin with one-

dimensional indexers.



Creating One-Dimensional Indexers

A one-dimensional indexer has this general form:



element-type

 this[int 



index

] {


   // The get accessor

    get {

        // return the value specifi ed by

 index

     }


    // The set accessor

    set {

       // set the value specifi ed by

 index

    }


}

245


CHAPTER

www.freepdf-books.com




246

 

P a r t   I :  



T h e   C #   L a n g u a g e

Here, 


element-type

 is the element type of the indexer. Thus, each element accessed by the 

indexer will be of type 

element-type.

 This type corresponds to the element type of an array. 

The parameter 

index

 receives the index of the element being accessed. Technically, this 

parameter does not have to be of type 

int

, but since indexers are typically used to provide 

array indexing, an integer type is customary.

Inside the body of the indexer two 



accessors

 are defined that are called 




Download 4,07 Mb.

Do'stlaringiz bilan baham:
1   ...   323   324   325   326   327   328   329   330   ...   1096




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