BitVector32 Структура
Определение
Важно!
Некоторые сведения относятся к предварительной версии продукта, в которую до выпуска могут быть внесены существенные изменения. Майкрософт не предоставляет никаких гарантий, явных или подразумеваемых, относительно приведенных здесь сведений.
Предоставляет простую структуру, в которой хранятся логические значения и небольшие целые числа в 32 битах памяти.
public value class BitVector32
public value class BitVector32 : IEquatable<System::Collections::Specialized::BitVector32>
public struct BitVector32
public struct BitVector32 : IEquatable<System.Collections.Specialized.BitVector32>
type BitVector32 = struct
Public Structure BitVector32
Public Structure BitVector32
Implements IEquatable(Of BitVector32)
- Наследование
- Реализации
Примеры
В следующем примере кода используется BitVector32 коллекция битовых флагов.
using System;
using System.Collections.Specialized;
public class SamplesBitVector32 {
public static void Main() {
// Creates and initializes a BitVector32 with all bit flags set to FALSE.
BitVector32 myBV = new BitVector32( 0 );
// Creates masks to isolate each of the first five bit flags.
int myBit1 = BitVector32.CreateMask();
int myBit2 = BitVector32.CreateMask( myBit1 );
int myBit3 = BitVector32.CreateMask( myBit2 );
int myBit4 = BitVector32.CreateMask( myBit3 );
int myBit5 = BitVector32.CreateMask( myBit4 );
// Sets the alternating bits to TRUE.
Console.WriteLine( "Setting alternating bits to TRUE:" );
Console.WriteLine( " Initial: {0}", myBV.ToString() );
myBV[myBit1] = true;
Console.WriteLine( " myBit1 = TRUE: {0}", myBV.ToString() );
myBV[myBit3] = true;
Console.WriteLine( " myBit3 = TRUE: {0}", myBV.ToString() );
myBV[myBit5] = true;
Console.WriteLine( " myBit5 = TRUE: {0}", myBV.ToString() );
}
}
/*
This code produces the following output.
Setting alternating bits to TRUE:
Initial: BitVector32{00000000000000000000000000000000}
myBit1 = TRUE: BitVector32{00000000000000000000000000000001}
myBit3 = TRUE: BitVector32{00000000000000000000000000000101}
myBit5 = TRUE: BitVector32{00000000000000000000000000010101}
*/
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)
' Sets the alternating bits to TRUE.
Console.WriteLine("Setting alternating bits to TRUE:")
Console.WriteLine(" Initial: {0}", myBV.ToString())
myBV(myBit1) = True
Console.WriteLine(" myBit1 = TRUE: {0}", myBV.ToString())
myBV(myBit3) = True
Console.WriteLine(" myBit3 = TRUE: {0}", myBV.ToString())
myBV(myBit5) = True
Console.WriteLine(" myBit5 = TRUE: {0}", myBV.ToString())
End Sub
End Class
' This code produces the following output.
'
' Setting alternating bits to TRUE:
' Initial: BitVector32{00000000000000000000000000000000}
' myBit1 = TRUE: BitVector32{00000000000000000000000000000001}
' myBit3 = TRUE: BitVector32{00000000000000000000000000000101}
' myBit5 = TRUE: BitVector32{00000000000000000000000000010101}
В следующем примере кода используется BitVector32 коллекция разделов.
using System;
using System.Collections.Specialized;
public class SamplesBitVector32 {
public static void Main() {
// Creates and initializes a BitVector32.
BitVector32 myBV = 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.
BitVector32.Section mySect1 = BitVector32.CreateSection( 6 );
BitVector32.Section mySect2 = BitVector32.CreateSection( 3, mySect1 );
BitVector32.Section mySect3 = BitVector32.CreateSection( 1, mySect2 );
BitVector32.Section mySect4 = BitVector32.CreateSection( 15, mySect3 );
// Displays the values of the sections.
Console.WriteLine( "Initial values:" );
Console.WriteLine( "\tmySect1: {0}", myBV[mySect1] );
Console.WriteLine( "\tmySect2: {0}", myBV[mySect2] );
Console.WriteLine( "\tmySect3: {0}", myBV[mySect3] );
Console.WriteLine( "\tmySect4: {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( "\tInitial: \t{0}", myBV.ToString() );
myBV[mySect1] = 5;
Console.WriteLine( "\tmySect1 = 5:\t{0}", myBV.ToString() );
myBV[mySect2] = 3;
Console.WriteLine( "\tmySect2 = 3:\t{0}", myBV.ToString() );
myBV[mySect3] = 1;
Console.WriteLine( "\tmySect3 = 1:\t{0}", myBV.ToString() );
myBV[mySect4] = 9;
Console.WriteLine( "\tmySect4 = 9:\t{0}", myBV.ToString() );
// Displays the values of the sections.
Console.WriteLine( "New values:" );
Console.WriteLine( "\tmySect1: {0}", myBV[mySect1] );
Console.WriteLine( "\tmySect2: {0}", myBV[mySect2] );
Console.WriteLine( "\tmySect3: {0}", myBV[mySect3] );
Console.WriteLine( "\tmySect4: {0}", myBV[mySect4] );
}
}
/*
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
*/
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
End Class
' 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
Комментарии
BitVector32 эффективнее, чем BitArray для логических значений и небольших целых чисел, которые используются внутри системы. При необходимости может BitArray увеличиваться неограниченное время, но он имеет нагрузку на память и производительность, необходимые экземпляру класса. В отличие от этого, используется BitVector32 только 32 бита.
Структура BitVector32 может быть настроена для хранения разделов для небольших целых чисел или битовых флагов для логических элементов, но не для обоих. Это BitVector32.Section окно в BitVector32 и состоит из наименьшего количества последовательных битов, которые могут содержать максимальное значение, указанное в CreateSection. Например, раздел с максимальным значением 1 состоит только из одного бита, в то время как раздел с максимальным значением 5 состоит из трех битов. Вы можете создать BitVector32.Section с максимальным значением 1, чтобы служить логическим, тем самым позволяя хранить целые числа и логические значения в том же BitVector32.
Некоторые члены можно использовать для BitVector32 настройки в качестве разделов, а другие элементы можно использовать для одного из них, настроенного как битовые флаги. Например, BitVector32.Item[] свойство является индексатором для BitVector32 настраиваемого в качестве разделов, а BitVector32.Item[] свойство — индексатором, BitVector32 настроенным как битовые флаги. CreateMask создает ряд маск, которые можно использовать для доступа к отдельным битам в настроенном BitVector32 как битовые флаги.
Использование маски для настроенного BitVector32 в качестве разделов может привести к непредвиденным результатам.
Конструкторы
| Имя | Описание |
|---|---|
| BitVector32(BitVector32) |
Инициализирует новый экземпляр BitVector32 структуры, содержащей данные, представленные в существующей BitVector32 структуре. |
| BitVector32(Int32) |
Инициализирует новый экземпляр BitVector32 структуры, содержащей данные, представленные целым числом. |
Свойства
| Имя | Описание |
|---|---|
| Data |
Возвращает значение целого BitVector32 числа. |
| Item[BitVector32+Section] |
Возвращает или задает значение, хранящееся в указанном.BitVector32.Section |
| Item[Int32] |
Возвращает или задает состояние битового флага, указанного указанной маской. |
Методы
| Имя | Описание |
|---|---|
| CreateMask() |
Создает первую маску в серии маск, которые можно использовать для извлечения отдельных битов в BitVector32 настроенном как битовые флаги. |
| CreateMask(Int32) |
Создает дополнительную маску после указанной маски в ряде маск, которые можно использовать для извлечения отдельных битов в настроенном BitVector32 как битовые флаги. |
| CreateSection(Int16, BitVector32+Section) |
Создает новый BitVector32.Section код, указанный BitVector32.Section в ряде разделов, содержащих небольшие целые числа. |
| CreateSection(Int16) |
Создает первый BitVector32.Section в серии разделов, содержащих небольшие целые числа. |
| Equals(BitVector32) |
Указывает, равен ли текущий экземпляр другому экземпляру того же типа. |
| Equals(Object) |
Определяет, равен BitVector32ли указанный объект. |
| GetHashCode() |
Служит хэш-функцией для .BitVector32 |
| ToString() |
Возвращает строку, представляющую текущий BitVector32. |
| ToString(BitVector32) |
Возвращает строку, представляющую указанный BitVector32объект. |