C# 0 The Complete Reference


high . The value of  high



Download 4,07 Mb.
Pdf ko'rish
bet353/1096
Sana23.01.2022
Hajmi4,07 Mb.
#402171
1   ...   349   350   351   352   353   354   355   356   ...   1096
Bog'liq
C-Sharp 3 The Complete Reference Herbert Schildt

high

. The value of 



high

 is then incremented because the indexes specified 

are inclusive. Next, a check is made to ensure that the upper index is greater than the lower 

index. If not, an error is reported and a one-element array is created. Next, storage for the 

array is allocated and assigned to 

a

. Then the 



Length

 property is set equal to the number of 

elements in the array. Finally, 

lowerBound

 and 


upperBound

 are set.

Next,

RangeArray

 implements its indexer, as shown here:

// This is the indexer for RangeArray.

public int this[int index] {

  // This is the get accessor.

  get {


    if(ok(index)) {

www.freepdf-books.com




268

 

P a r t   I :  



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

      Error = false;

      return a[index - lowerBound];

    } else {

      Error = true;

      return 0;

    }

  }


  // This is the set accessor.

  set {


    if(ok(index)) {

      a[index - lowerBound] = value;

      Error = false;

    }


    else Error = true;

  }


}

This indexer is similar to the one used by 



FailSoftArray

, with one important exception. 

Notice the expression that indexes 

a

. It is


index - lowerBound

This expression transforms the index passed in 



index

 into a zero-based index suitable for 

use on 

a

. This expression works whether 



lowerBound

 is positive, negative, or zero.

The

ok( )

 method is shown here:

// Return true if index is within bounds.

private bool ok(int index) {

  if(index >= lowerBound & index <= upperBound) return true;

  return false;

}

It is similar to the one used by 



FailSoftArray

 except that the range is checked by testing it 

against the values in 


Download 4,07 Mb.

Do'stlaringiz bilan baham:
1   ...   349   350   351   352   353   354   355   356   ...   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