本文整理汇总了C#中System.Collections.BitArray.And方法的典型用法代码示例。如果您正苦于以下问题:C# BitArray.And方法的具体用法?C# BitArray.And怎么用?C# BitArray.And使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Collections.BitArray
的用法示例。
在下文中一共展示了BitArray.And方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Main
//引入命名空间
using System;
using System.Collections;
public class SamplesBitArray {
public static void Main() {
// Creates and initializes two BitArrays of the same size.
BitArray myBA1 = new BitArray( 4 );
BitArray myBA2 = new BitArray( 4 );
myBA1[0] = myBA1[1] = false;
myBA1[2] = myBA1[3] = true;
myBA2[0] = myBA2[2] = false;
myBA2[1] = myBA2[3] = true;
// Performs a bitwise AND operation between BitArray instances of the same size.
Console.WriteLine( "Initial values" );
Console.Write( "myBA1:" );
PrintValues( myBA1, 8 );
Console.Write( "myBA2:" );
PrintValues( myBA2, 8 );
Console.WriteLine();
Console.WriteLine( "Result" );
Console.Write( "AND:" );
PrintValues( myBA1.And( myBA2 ), 8 );
Console.WriteLine();
Console.WriteLine( "After AND" );
Console.Write( "myBA1:" );
PrintValues( myBA1, 8 );
Console.Write( "myBA2:" );
PrintValues( myBA2, 8 );
Console.WriteLine();
// Performing AND between BitArray instances of different sizes returns an exception.
try {
BitArray myBA3 = new BitArray( 8 );
myBA3[0] = myBA3[1] = myBA3[2] = myBA3[3] = false;
myBA3[4] = myBA3[5] = myBA3[6] = myBA3[7] = true;
myBA1.And( myBA3 );
} catch ( Exception myException ) {
Console.WriteLine("Exception: " + myException.ToString());
}
}
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();
}
}
输出:
Initial values myBA1: False False True True myBA2: False True False True Result AND: False False False True After AND myBA1: False False False True myBA2: False True False True Exception: System.ArgumentException: Array lengths must be the same. at System.Collections.BitArray.And(BitArray value) at SamplesBitArray.Main()