本文整理汇总了C#中BitArray.EnsureCapacity方法的典型用法代码示例。如果您正苦于以下问题:C# BitArray.EnsureCapacity方法的具体用法?C# BitArray.EnsureCapacity怎么用?C# BitArray.EnsureCapacity使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类BitArray
的用法示例。
在下文中一共展示了BitArray.EnsureCapacity方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetSetBits
public void GetSetBits()
{
BitArray array = new BitArray(false, 15);
for (int x = 0; x < 15; x++)
{
if (array[x])
throw new Exception();
}
for (int x = 0; x < 15; x++)
{
if (array.GetBitUnchecked(x))
throw new Exception();
}
array[1] = true;
if(array.TrySetBit(1))
throw new Exception();
if (!array.TrySetBit(2))
throw new Exception();
if (array.TrySetBit(2))
throw new Exception();
if (!array.TryClearBit(2))
throw new Exception();
if (array.TryClearBit(2))
throw new Exception();
//Here, bit 1 is set.
if (!array.AreAllBitsSet(1,1))
throw new Exception();
if (array.AreAllBitsSet(1,3))
throw new Exception();
if (!array.AreAllBitsCleared(2,8))
throw new Exception();
if (array.AreAllBitsCleared(0, 8))
throw new Exception();
array.SetBits(1,8);
if (!array.AreAllBitsSet(1,8))
throw new Exception();
array.ClearBits(1, 8);
if (!array.AreAllBitsCleared(1, 8))
throw new Exception();
array.EnsureCapacity(62);
if (!array.AreAllBitsCleared(1, 8))
throw new Exception();
array.EnsureCapacity(1000);
if (!array.AreAllBitsCleared(62, 500))
throw new Exception();
}
示例2: FindBits
public void FindBits()
{
BitArray arraySet = new BitArray(true, 15);
BitArray arrayClear = new BitArray(false, 15);
if (arraySet.FindClearedBit() != -1)
throw new Exception();
if (arrayClear.FindSetBit() != -1)
throw new Exception();
int count = 0;
foreach (var set in arraySet.GetAllSetBits())
{
if (set != count)
throw new Exception();
count++;
}
count = 0;
foreach (var set in arrayClear.GetAllClearedBits())
{
if (set != count)
throw new Exception();
count++;
}
if (arrayClear.GetAllSetBits().Count() != 0)
throw new Exception();
if (arraySet.GetAllClearedBits().Count() != 0)
throw new Exception();
arraySet.EnsureCapacity(300);
if (!arraySet.AreAllBitsSet(62, 200))
throw new Exception();
if (arraySet.ClearCount != 0)
throw new Exception();
}