BitVector32.CreateMask Method ()


The .NET API Reference documentation has a new home. Visit the .NET API Browser on to see the new experience.

Creates the first mask in a series of masks that can be used to retrieve individual bits in a BitVector32 that is set up as bit flags.

Namespace:   System.Collections.Specialized
Assembly:  System (in System.dll)

Public Shared Function CreateMask As Integer

Return Value

Type: System.Int32

A mask that isolates the first bit flag in the BitVector32.

Use CreateMask() to create the first mask in a series and CreateMask(int) for all subsequent masks.

Multiple masks can be created to refer to the same bit flag.

The resulting mask isolates only one bit flag in the BitVector32. You can combine masks using the bitwise OR operation to create a mask that isolates multiple bit flags in the BitVector32.

Using a mask on a BitVector32 that is set up as sections might cause unexpected results.

This method is an O(1) operation.

The following code example shows how to create and use masks.

Imports System
Imports System.Collections.Specialized

Public Class SamplesBitVector32

   Public Shared Sub Main()

      ' Creates and initializes a BitVector32 with all bit flags set to FALSE.
      Dim myBV As New BitVector32(0)

      ' Creates masks to isolate each of the first five bit flags.
      Dim myBit1 As Integer = BitVector32.CreateMask()
      Dim myBit2 As Integer = BitVector32.CreateMask(myBit1)
      Dim myBit3 As Integer = BitVector32.CreateMask(myBit2)
      Dim myBit4 As Integer = BitVector32.CreateMask(myBit3)
      Dim myBit5 As Integer = BitVector32.CreateMask(myBit4)
      Console.WriteLine("Initial:               " + ControlChars.Tab + "{0}", myBV.ToString())

      ' Sets the third bit to TRUE.
      myBV(myBit3) = True
      Console.WriteLine("myBit3 = TRUE          " + ControlChars.Tab + "{0}", myBV.ToString())

      ' Combines two masks to access multiple bits at a time.
      myBV((myBit4 + myBit5)) = True
      Console.WriteLine("myBit4 + myBit5 = TRUE " + ControlChars.Tab + "{0}", myBV.ToString())
      myBV((myBit1 Or myBit2)) = True
      Console.WriteLine("myBit1 | myBit2 = TRUE " + ControlChars.Tab + "{0}", myBV.ToString())

   End Sub 'Main 

End Class 'SamplesBitVector32

' This code produces the following output.
' Initial:                BitVector32{00000000000000000000000000000000}
' myBit3 = TRUE           BitVector32{00000000000000000000000000000100}
' myBit4 + myBit5 = TRUE  BitVector32{00000000000000000000000000011100}
' myBit1 | myBit2 = TRUE  BitVector32{00000000000000000000000000011111}

Universal Windows Platform
Available since 10
.NET Framework
Available since 1.1
Return to top