C# 0 The Complete Reference


PwrOfTwo  includes a  get



Download 4,07 Mb.
Pdf ko'rish
bet333/1096
Sana23.01.2022
Hajmi4,07 Mb.
#402171
1   ...   329   330   331   332   333   334   335   336   ...   1096
Bog'liq
C-Sharp 3 The Complete Reference Herbert Schildt

PwrOfTwo

 includes a 



get

 accessor, but no 



set

 accessor. As 

explained, this means that the indexer is read-only. Thus, a 

PwrOfTwo

 object can be used 

on the right side of an assignment statement, but not on the left. For example, attempting 

to add this statement to the preceding program won’t work:

pwr[0] = 11; // won't compile

This statement will cause a compilation error because no 



set

 accessor is defined for the 

indexer.

There are two important restrictions to using indexers. First, because an indexer does 

not define a storage location, a value produced by an indexer cannot be passed as a 

ref

 or 


out

 parameter to a method. Second, an indexer must be an instance member of its class; it 

cannot be declared 

static

.

Multidimensional Indexers

You can create indexers for multidimensional arrays, too. For example, here is a two-

dimensional fail-soft array. Pay close attention to the way that the indexer is declared.

// A two-dimensional fail-soft array.

using System;

class FailSoftArray2D {

  int[,] a; // reference to underlying 2D array

  int rows, cols; // dimensions

  public int Length; // Length is public

  public bool ErrFlag; // indicates outcome of last operation

  // Construct array given its dimensions.

  public FailSoftArray2D(int r, int c) {

www.freepdf-books.com




Download 4,07 Mb.

Do'stlaringiz bilan baham:
1   ...   329   330   331   332   333   334   335   336   ...   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