BitVector32.CreateSection Method (Int16, BitVector32.Section)
Creates a new BitVector32.Section following the specified BitVector32.Section in a series of sections that contain small integers.
Namespace: System.Collections.Specialized
Assembly: System (in System.dll)
'Declaration Public Shared Function CreateSection ( _ maxValue As Short, _ previous As BitVector32.Section _ ) As BitVector32.Section
Parameters
- maxValue
- Type: System.Int16
A 16-bit signed integer that specifies the maximum value for the new BitVector32.Section.
- previous
- Type: System.Collections.Specialized.BitVector32.Section
The previous BitVector32.Section in the BitVector32.
Return Value
Type: System.Collections.Specialized.BitVector32.SectionA BitVector32.Section that can hold a number from zero to maxValue.
| Exception | Condition |
|---|---|
| ArgumentException | maxValue is less than 1. |
| InvalidOperationException | previous includes the final bit in the BitVector32. -or- maxValue is greater than the highest value that can be represented by the number of bits after previous. |
A BitVector32.Section is a window into the BitVector32 and is composed of the smallest number of consecutive bits that can contain the maximum value specified in CreateSection. For example, a section with a maximum value of 1 is composed of only one bit, whereas a section with a maximum value of 5 is composed of three bits. You can create a BitVector32.Section with a maximum value of 1 to serve as a Boolean, thereby allowing you to store integers and Booleans in the same BitVector32.
If sections already exist after previous in the BitVector32, those sections are still accessible; however, overlapping sections might cause unexpected results.
This method is an O(1) operation.
The following code example uses a BitVector32 as a collection of sections.
Imports System Imports System.Collections.Specialized Public Class SamplesBitVector32 Public Shared Sub Main() ' Creates and initializes a BitVector32. Dim myBV As New BitVector32(0) ' Creates four sections in the BitVector32 with maximum values 6, 3, 1, and 15. ' mySect3, which uses exactly one bit, can also be used as a bit flag. Dim mySect1 As BitVector32.Section = BitVector32.CreateSection(6) Dim mySect2 As BitVector32.Section = BitVector32.CreateSection(3, mySect1) Dim mySect3 As BitVector32.Section = BitVector32.CreateSection(1, mySect2) Dim mySect4 As BitVector32.Section = BitVector32.CreateSection(15, mySect3) ' Displays the values of the sections. Console.WriteLine("Initial values:") Console.WriteLine(ControlChars.Tab + "mySect1: {0}", myBV(mySect1)) Console.WriteLine(ControlChars.Tab + "mySect2: {0}", myBV(mySect2)) Console.WriteLine(ControlChars.Tab + "mySect3: {0}", myBV(mySect3)) Console.WriteLine(ControlChars.Tab + "mySect4: {0}", myBV(mySect4)) ' Sets each section to a new value and displays the value of the BitVector32 at each step. Console.WriteLine("Changing the values of each section:") Console.WriteLine(ControlChars.Tab + "Initial: " + ControlChars.Tab + "{0}", myBV.ToString()) myBV(mySect1) = 5 Console.WriteLine(ControlChars.Tab + "mySect1 = 5:" + ControlChars.Tab + "{0}", myBV.ToString()) myBV(mySect2) = 3 Console.WriteLine(ControlChars.Tab + "mySect2 = 3:" + ControlChars.Tab + "{0}", myBV.ToString()) myBV(mySect3) = 1 Console.WriteLine(ControlChars.Tab + "mySect3 = 1:" + ControlChars.Tab + "{0}", myBV.ToString()) myBV(mySect4) = 9 Console.WriteLine(ControlChars.Tab + "mySect4 = 9:" + ControlChars.Tab + "{0}", myBV.ToString()) ' Displays the values of the sections. Console.WriteLine("New values:") Console.WriteLine(ControlChars.Tab + "mySect1: {0}", myBV(mySect1)) Console.WriteLine(ControlChars.Tab + "mySect2: {0}", myBV(mySect2)) Console.WriteLine(ControlChars.Tab + "mySect3: {0}", myBV(mySect3)) Console.WriteLine(ControlChars.Tab + "mySect4: {0}", myBV(mySect4)) End Sub 'Main End Class 'SamplesBitVector32 ' This code produces the following output. ' ' Initial values: ' mySect1: 0 ' mySect2: 0 ' mySect3: 0 ' mySect4: 0 ' Changing the values of each section: ' Initial: BitVector32{00000000000000000000000000000000} ' mySect1 = 5: BitVector32{00000000000000000000000000000101} ' mySect2 = 3: BitVector32{00000000000000000000000000011101} ' mySect3 = 1: BitVector32{00000000000000000000000000111101} ' mySect4 = 9: BitVector32{00000000000000000000001001111101} ' New values: ' mySect1: 5 ' mySect2: 3 ' mySect3: 1 ' mySect4: 9
Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)
The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.