BitVector32.Section Структура

Определение

Представляет раздел вектора, который может содержать целое число.

public: value class BitVector32::Section
public: value class BitVector32::Section : IEquatable<System::Collections::Specialized::BitVector32::Section>
public struct BitVector32.Section
public readonly struct BitVector32.Section
public readonly struct BitVector32.Section : IEquatable<System.Collections.Specialized.BitVector32.Section>
type BitVector32.Section = struct
Public Structure BitVector32.Section
Public Structure BitVector32.Section
Implements IEquatable(Of BitVector32.Section)
Наследование
BitVector32.Section
Реализации

Примеры

В следующем примере кода используется BitVector32 в качестве коллекции разделов.

#using <system.dll>

using namespace System;
using namespace System::Collections::Specialized;

int main()
{
   // Creates and initializes a BitVector32.
   BitVector32 myBV(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 );
   myBV[ mySect1 ] = 5;
   Console::WriteLine( "\tmySect1 = 5:\t {0}", myBV );
   myBV[ mySect2 ] = 3;
   Console::WriteLine( "\tmySect2 = 3:\t {0}", myBV );
   myBV[ mySect3 ] = 1;
   Console::WriteLine( "\tmySect3 = 1:\t {0}", myBV );
   myBV[ mySect4 ] = 9;
   Console::WriteLine( "\tmySect4 = 9:\t {0}", myBV );

   // 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

*/
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

Комментарии

Используется для CreateSection определения нового раздела. A BitVector32.Section — это окно в и BitVector32 состоит из наименьшего числа последовательных битов, которые могут содержать максимальное значение, указанное в CreateSection. Например, раздел с максимальным значением 1 состоит только из одного бита, а раздел с максимальным значением 5 состоит из трех битов. Вы можете создать BitVector32.Section значение с максимальным значением 1, которое будет использоваться в качестве логического значения, что позволяет хранить целые числа и логические значения в одном и том же BitVector32.

Свойства

Mask

Получает маску, которая изолирует этот раздел в структуре BitVector32.

Offset

Получает смещение этого раздела от начала структуры BitVector32.

Методы

Equals(BitVector32+Section)

Определяет, является ли указанный объект BitVector32.Section тем же самым, что и текущий объект BitVector32.Section.

Equals(Object)

Определяет, является ли указанный объект тем же самым, что и текущий объект BitVector32.Section.

GetHashCode()

Служит хэш-функцией текущего класса BitVector32.Section для использования в алгоритмах и структурах данных хеширования, например в хэш-таблице.

ToString()

Возвращает строку, которая представляет текущий объект BitVector32.Section.

ToString(BitVector32+Section)

Возвращает строку, представляющую указанный объект BitVector32.Section.

Операторы

Equality(BitVector32+Section, BitVector32+Section)

Определение равенства двух заданных объектов BitVector32.Section.

Inequality(BitVector32+Section, BitVector32+Section)

Определяет, имеют ли два объекта BitVector32.Section различные значения.

Применяется к

См. также раздел