×

VB.Net基本教程

VB.Net 环境设置VB.Net 程序结构VB.Net 基本语法VB.Net 数据类型VB.Net 变量VB.Net 常数和枚举VB.Net 修饰符VB.Net 声明VB.Net 指令VB.Net 运算符VB.Net 决策VB.Net 循环VB.Net 字符串VB.Net 日期和时间VB.Net 数组VB.Net 集合VB.Net 函数VB.Net Sub过程(子程序)VB.Net 类与对象VB.Net 异常处理VB.Net 文件处理VB.Net 基本控制VB.Net 对话框VB.Net 高级表单VB.Net 事件处理

VB.Net 高级教程

VB.Net 正则表达式VB.Net 数据库访问VB.Net Excel工作表VB.Net 发送邮件VB.Net XML处理VB.Net Web编程

VB.Net 有用的资源

VB.Net 有用资源

VB.Net BitArray


VB.Net  集合VB.Net 集合


BitArray类管理位值的压缩数组,它表示为布尔值,其中true表示该位为(1),false表示位为off(0)。

它用于需要存储位但不提前知道位数。 您可以通过使用从零开始的整数索引来访问BitArray集合中的项目。

BitArray类的属性和方法

下表列出了BitArray类的一些常用属性:

属性 描述
Count Gets the number of elements contained in the BitArray.
获取BitArray中包含的元素数。
IsReadOnly Gets a value indicating whether the BitArray is read-only.
获取一个指示BitArray是否为只读的值。
Item Gets or sets the value of the bit at a specific position in the BitArray.
获取或设置位在BitArray中特定位置的值。
Length Gets or sets the number of elements in the BitArray.
获取或设置BitArray中的元素数。

下表列出了BitArray类的一些常用方法:
S.N 方法名称和用途
1

Public Function And (value As BitArray) As BitArray

Performs the bitwise AND operation on the elements in the current BitArray against the corresponding elements in the specified BitArray.

对当前BitArray中的元素与指定的BitArray中的相应元素执行按位AND运算。

2

Public Function Get (index As Integer) As Boolean

Gets the value of the bit at a specific position in the BitArray.

获取位在BitArray中特定位置的值。

3

Public Function Not As BitArray

Inverts all the bit values in the current BitArray, so that elements set to true are changed to false, and elements set to false are changed to true.

反转当前BitArray中的所有位值,以便将设置为true的元素更改为false,将设置为false的元素更改为true。

4

Public Function Or (value As BitArray) As BitArray

Performs the bitwise OR operation on the elements in the current BitArray against the corresponding elements in the specified BitArray.

对当前BitArray中的元素与指定的BitArray中的相应元素执行按位或运算。

5

Public Sub Set (index As Integer, value As Boolean )

Sets the bit at a specific position in the BitArray to the specified value.

将BitArray中特定位置的位设置为指定值。

6

Public Sub SetAll (value As Boolean)

Sets all bits in the BitArray to the specified value.

将BitArray中的所有位设置为指定的值。

7

Public Function Xor (value As BitArray) As BitArray

Performs the bitwise eXclusive OR operation on the elements in the current BitArray against the corresponding elements in the specified BitArray.

对当前BitArray中的元素与指定的BitArray中的相应元素执行逐位异或操作。


示例:

下面的例子演示了使用BitArray类:
Module collections
   Sub Main()
      'creating two  bit arrays of size 8
      Dim ba1 As BitArray = New BitArray(8)
      Dim ba2 As BitArray = New BitArray(8)
      Dim a() As Byte = {60}
      Dim b() As Byte = {13}
      'storing the values 60, and 13 into the bit arrays
      ba1 = New BitArray(a)
      ba2 = New BitArray(b)
      'content of ba1
      Console.WriteLine("Bit array ba1: 60")
      Dim i As Integer
      For i = 0 To ba1.Count
          Console.Write("{0 } ", ba1(i))
      Next i
      Console.WriteLine()
      'content of ba2
      Console.WriteLine("Bit array ba2: 13")
      For i = 0 To ba2.Count
          Console.Write("{0 } ", ba2(i))
      Next i
      Console.WriteLine()
      Dim ba3 As BitArray = New BitArray(8)
      ba3 = ba1.And(ba2)
      'content of ba3
      Console.WriteLine("Bit array ba3 after AND operation: 12")
      For i = 0 To ba3.Count
          Console.Write("{0 } ", ba3(i))
      Next i
      Console.WriteLine()
      ba3 = ba1.Or(ba2)
      'content of ba3
      Console.WriteLine("Bit array ba3 after OR operation: 61")
      For i = 0 To ba3.Count
          Console.Write("{0 } ", ba3(i))
      Next i
      Console.WriteLine()
      Console.ReadKey()
   End Sub
End Module

当上述代码被编译和执行时,它产生以下结果:
Bit array ba1: 60 
False False True True True True False False 
Bit array ba2: 13
True False True True False False False False 
Bit array ba3 after AND operation: 12
False False True True False False False False 
Bit array ba3 after OR operation: 61
True False True True False False False False 


VB.Net  集合VB.Net 集合


分类导航

关注微信下载离线手册

bootwiki移动版 bootwiki
(群号:472910771)