BitArray 类
源代码(截取自MSDN):
using System;
using System.Collections;
public class SamplesBitArray {
public static void Main() {
// Creates and initializes several BitArrays.
byte[] myBytes = new byte[5] { 1, 2, 3, 4, 5 };
BitArray myBA3 = new BitArray( myBytes );
int[] myInts = new int[5] { 6, 7, 8, 9, 10 };
BitArray myBA5 = new BitArray( myInts );
// Displays the properties and values of the BitArrays.
Console.WriteLine( "myBA3" );
Console.WriteLine( " Count: {0}", myBA3.Count );
Console.WriteLine( " Length: {0}", myBA3.Length );
Console.WriteLine( " Values:" );
PrintValues( myBA3, 8 );
Console.WriteLine( "myBA5" );
Console.WriteLine( " Count: {0}", myBA5.Count );
Console.WriteLine( " Length: {0}", myBA5.Length );
Console.WriteLine( " Values:" );
PrintValues( myBA5, 8 );
}
public static void PrintValues( IEnumerable myList, int myWidth ) {
int i = myWidth;
foreach ( Object obj in myList ) {
if ( i <= 0 ) {
i = myWidth;
Console.WriteLine();
}
i--;
Console.Write( "{0,8}", obj );
}
Console.WriteLine();
}
}
运行结果:
myBA3
Count: 40
Length: 40
Values:
True False False False False False False False
False True False False False False False False
True True False False False False False False
False False True False False False False False
True False True False False False False False
myBA5
Count: 160
Length: 160
Values:
False True True False False False False False
False False False False False False False False
False False False False False False False False
False False False False False False False False
True True True False False False False False
False False False False False False False False
False False False False False False False False
False False False False False False False False
False False False True False False False False
False False False False False False False False
False False False False False False False False
False False False False False False False False
True False False True False False False False
False False False False False False False False
False False False False False False False False
False False False False False False False False
False True False True False False False False
False False False False False False False False
False False False False False False False False
False False False False False False False False
疑问:myBA3 与myBA5差不多为什么myBA5的Count、Length、Values会相差这么大?
本人的基础不是很好,看了MSDN还是有这样的疑问,请各位朋友耐心而详细解答一下,或者给个说明的链接也行,谢谢!
---