C# 0 The Complete Reference


PART II C h a p t e r   2 4



Download 4,07 Mb.
Pdf ko'rish
bet963/1096
Sana23.01.2022
Hajmi4,07 Mb.
#402171
1   ...   959   960   961   962   963   964   965   966   ...   1096
Bog'liq
C-Sharp 3 The Complete Reference Herbert Schildt


PART II

C h a p t e r   2 4 :  

C o l l e c t i o n s ,   E n u m e r a t o r s ,   a n d   I t e r a t o r s    

773


To the properties specified by the interfaces that it implements, 

BitArray

 adds 


Length

,

which is shown here:



public int Length { get; set; }

Length

 sets or obtains the number of bits in the collection. Thus, 



Length

 gives the same 

value as does the standard 

Count

 property, which is defined for all collections. However, 



Count

 is read-only, but 



Length

 is not. Thus, 



Length

 can be used to change the size of a 



BitArray

. If you shorten a 



BitArray

, bits are truncated from the high-order end. If you 

lengthen a 

BitArray

, false bits are added to the high-order end.



BitArray

 defines the following indexer:

public bool this[int 

idx

] { get; set; }

You can use this indexer to get or set the value of an element.

Here is an example that demonstrates 



BitArray

:

// Demonstrate BitArray.



using System;

using System.Collections;

class BADemo {

  public static void ShowBits(string rem,

                         BitArray bits) {

    Console.WriteLine(rem);

    for(int i=0; i < bits.Count; i++)

      Console.Write("{0, -6} ", bits[i]);

    Console.WriteLine("\n");

  }


  static void Main() {

    BitArray ba = new BitArray(8);

    byte[] b = { 67 };

    BitArray ba2 = new BitArray(b);

    ShowBits("Original contents of ba:", ba);

    ba = ba.Not();

    ShowBits("Contents of ba after Not:", ba);

    ShowBits("Contents of ba2:", ba2);

    BitArray ba3 = ba.Xor(ba2);

    ShowBits("Result of ba XOR ba2:", ba3);

  }

}

The output is shown here:



Original contents of ba:

False  False  False  False  False  False  False  False

www.freepdf-books.com



774

 

P a r t   I I :  



E x p l o r i n g   t h e   C #   L i b r a r y

Contents of ba after Not:

True   True   True   True   True   True   True   True

Contents of ba2:

True   True   False  False  False  False  True   False

Result of ba XOR ba2:

False  False  True   True   True   True   False  True


Download 4,07 Mb.

Do'stlaringiz bilan baham:
1   ...   959   960   961   962   963   964   965   966   ...   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