System.Collections.Specialized.BitVector32 Structure

Assembly: System.dll
Namespace: System.Collections.Specialized
Summary
Provides a simple structure that stores Boolean values and small integers in 32 bits of memory.
C# Syntax:
public struct BitVector32
Remarks
BitVector32 is more efficient than BitArray for Boolean values and small integers that are used internally. A BitArray can grow indefinitely as needed, but it has the memory and performance overhead that a class instance requires. In contrast, a BitVector32 uses only 32 bits.

A BitVector32 structure can be set up to contain either sections for small integers or bit flags for Booleans, but not both. 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 BitVector32.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.

Some members can be used for a BitVector32 that is set up as sections, while other members can be used for one that is set up as bit flags. For example, the BitVector32.Item [Section] property is the indexer for a BitVector32 that is set up as sections, and the BitVector32.Item [int] property is the indexer for a BitVector32 that is set up as bit flags. BitVector32.CreateMask creates a series of masks that can be used to access individual bits in a BitVector32 that is set up as bit flags.

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

Example
The following example shows the standard usage of a bit vector.
using System;
using System.Collections.Specialized;
using System.Windows.Forms;

public class Form1: Form
{
 protected TextBox textBox1;
// Creates three sections for a bit vector.
 private static readonly BitVector32.Section first = 
    BitVector32.CreateSection(2);
 private static readonly BitVector32.Section second = 
    BitVector32.CreateSection(1, first);
 private static readonly BitVector32.Section third = 
    BitVector32.CreateSection(5, second);
 
 // Creates two masks for the bit vector.
 private static readonly int MaskOne = BitVector32.CreateMask();
 private static readonly int MaskTwo = BitVector32.CreateMask(MaskOne);

 private void MyMethod()
 { 
 // Creates a new bit vector, using the first and third sections.
 // The first section has a maximum of two as defined above.
 BitVector32 b = new BitVector32(); b[first] = 1;
 // The third section has a maximum of five.
 b[third] = 3; 
 
 // Creates another bit vector, with Mask One.
 BitVector32 anotherB = new BitVector32(); 
 anotherB[MaskOne] = true;
 }   
}

    
See also:
System.Collections.Specialized Namespace | BitArray

System.Collections.Specialized.BitVector32 Member List:

Public Constructors
ctor #1 Overloaded:
.ctor(BitVector32 value)

Initializes a new instance of the BitVector32 structure containing the data represented in an existing BitVector32 structure.
ctor #2 Overloaded:
.ctor(int data)

Initializes a new instance of the BitVector32 structure containing the data represented in an integer.
Public Properties
Data Read-only

Gets the value of the BitVector32 as an integer.
Item Read-write

Overloaded:
Item[BitVector32.Section section] {get

Gets or sets the value stored in the specified BitVector32.Section.
Item Read-write

Overloaded:
Item[int bit] {get

Gets or sets the state of the bit flag indicated by the specified mask.
Public Methods
CreateMask Overloaded:
CreateMask()

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.
CreateMask Overloaded:
CreateMask(int previous)

Creates an additional mask following the specified mask in a series of masks that can be used to retrieve individual bits in a BitVector32 that is set up as bit flags.
CreateSection Overloaded:
CreateSection(short maxValue)

Creates the first BitVector32.Section in a series of sections that contain small integers.
CreateSection Overloaded:
CreateSection(short maxValue, BitVector32.Section previous)

Creates a new BitVector32.Section following the specified BitVector32.Section in a series of sections that contain small integers.
Equals Overridden:
Determines whether the specified object is equal to the BitVector32.
GetHashCode Overridden:
Serves as a hash function for the BitVector32.
GetType
(inherited from System.Object)
See base class member description: System.Object.GetType

Derived from System.Object, the primary base class for all objects.
ToString Overloaded:
ToString()

Overridden:
Supports the Shared Source CLI infrastructure and is not intended to be used directly from your code
ToString Overloaded:
ToString(BitVector32 value)

Supports the Shared Source CLI infrastructure and is not intended to be used directly from your code
Protected Methods
Finalize
(inherited from System.Object)
See base class member description: System.Object.Finalize

Derived from System.Object, the primary base class for all objects.
MemberwiseClone
(inherited from System.Object)
See base class member description: System.Object.MemberwiseClone

Derived from System.Object, the primary base class for all objects.

Hierarchy:


System.Collections.Specialized.BitVector32 Member Details

Overloaded ctor #1
Summary
Initializes a new instance of the BitVector32 structure containing the data represented in an existing BitVector32 structure.
C# Syntax:
public BitVector32(BitVector32(
   BitVector32 value
);
Parameters:

value

A BitVector32 structure that contains the data to copy.

Return to top


Overloaded ctor #2
Summary
Initializes a new instance of the BitVector32 structure containing the data represented in an integer.
C# Syntax:
public BitVector32(
   int data
);
Parameters:

data

An integer representing the data of the new BitVector32.

Return to top


Property: Data (read-only)
Summary
Gets the value of the BitVector32 as an integer.
C# Syntax:
public int Data {get;}
Remarks
To access the value of the individual sections or bit flags, use the BitVector32.Item property.
See also:
BitVector32.Item

Return to top


Overloaded Property: Item (read-write)
Summary
Gets or sets the value stored in the specified BitVector32.Section.
C# Syntax:
public int this[BitVector32.Section section] {get; set;}
Parameters:

section

A BitVector32.Section that contains the value to get or set.

Remarks
The BitVector32.Item [Section] property is the indexer for a BitVector32 that is set up as sections, and the BitVector32.Item [int] property is the indexer for a BitVector32 that is set up as bit flags.

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 BitVector32.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.

See also:
BitVector32.CreateSection | BitVector32.Section

Return to top


Overloaded Property: Item (read-write)
Summary
Gets or sets the state of the bit flag indicated by the specified mask.
C# Syntax:
public bool this[int bit] {get; set;}
Parameters:

bit

A mask that indicates the bit to get or set.

Remarks
The BitVector32.Item [Section] property is the indexer for a BitVector32 that is set up as sections, and the BitVector32.Item [int] property is the indexer for a BitVector32 that is set up as bit flags.

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

See also:
BitVector32.CreateMask

Return to top


Overloaded Method: CreateMask()
Summary
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.
C# Syntax:
public static int CreateMask();
Return Value:
A mask that isolates the first bit flag in the BitVector32.
Remarks
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.

Return to top


Overloaded Method: CreateMask(
   int previous
)
Summary
Creates an additional mask following the specified mask in a series of masks that can be used to retrieve individual bits in a BitVector32 that is set up as bit flags.
C# Syntax:
public static int CreateMask(
   int previous
);
Parameters:

previous

The mask that indicates the previous bit flag.

Return Value:
A mask that isolates the bit flag following the one that previous points to in BitVector32.
Exceptions
Exception Type Condition
InvalidOperationException previous indicates the last bit flag in the BitVector32.
Remarks
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.

Return to top


Overloaded Method: CreateSection(
   short maxValue
)
Summary
Creates the first BitVector32.Section in a series of sections that contain small integers.
C# Syntax:
public static Section CreateSection(
   short maxValue
);
Parameters:

maxValue

A 16-bit signed integer that specifies the maximum value for the new BitVector32.Section.

Return Value:
A BitVector32.Section that can hold a number from zero to maxValue.
Exceptions
Exception Type Condition
ArgumentException maxValue is less than 1.
Remarks
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 BitVector32.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 in the BitVector32, those sections are still accessible; however, overlapping sections might cause unexpected results.

Return to top


Overloaded Method: CreateSection(
   short maxValue,
   BitVector32.Section previous
)
Summary
Creates a new BitVector32.Section following the specified BitVector32.Section in a series of sections that contain small integers.
C# Syntax:
public static Section CreateSection(
   short maxValue,
   BitVector32.Section previous
);
Parameters:

maxValue

A 16-bit signed integer that specifies the maximum value for the new BitVector32.Section.

previous

The previous BitVector32.Section in the BitVector32.

Return Value:
A BitVector32.Section that can hold a number from zero to maxValue.
Exceptions
Exception Type 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.

Remarks
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 BitVector32.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.

Return to top


Overridden Method: Equals(
   object o
)
Summary
Determines whether the specified object is equal to the BitVector32.
C# Syntax:
public override bool Equals(
   object o
);
Parameters:

o

The object to compare with the current BitVector32.

Return Value:
true if the specified object is equal to the BitVector32; otherwise, false.
Remarks
The object o is considered equal to the BitVector32 if the type of o is compatible with the BitVector32 type and if the value of o is equal to the value of BitVector32.Data.

Return to top


Method: Finalize()
Inherited
See base class member description: System.Object.Finalize
C# Syntax:
~BitVector32();

For more information on members inherited from System.Object click on the link above.

Return to top


Overridden Method: GetHashCode()
Summary
Serves as a hash function for the BitVector32.
C# Syntax:
public override int GetHashCode();
Return Value:
A hash code for the BitVector32.
Remarks
The hash code of a BitVector32 is based on the value of BitVector32.Data. Two instances of BitVector32 with the same value for BitVector32.Data will also generate the same hash code.

Return to top


Method: GetType()
Inherited
See base class member description: System.Object.GetType
C# Syntax:
public Type GetType();

For more information on members inherited from System.Object click on the link above.

Return to top


Method: MemberwiseClone()
Inherited
See base class member description: System.Object.MemberwiseClone
C# Syntax:
protected object MemberwiseClone();

For more information on members inherited from System.Object click on the link above.

Return to top


Overloaded Method: ToString()
Summary
Supports the Shared Source CLI infrastructure and is not intended to be used directly from your code
This type supports the Shared Source CLI infrastructure and is not intended to be used directly from your code.
C# Syntax:
public override string ToString();

Return to top


Overloaded Method: ToString(
   BitVector32 value
)
Summary
Supports the Shared Source CLI infrastructure and is not intended to be used directly from your code
This type supports the Shared Source CLI infrastructure and is not intended to be used directly from your code.
C# Syntax:
public static string ToString(
   BitVector32 value
);
Parameters:

value

Return to top


Top of page

Copyright (c) 2002 Microsoft Corporation. All rights reserved.