BitVector32.Section 结构

定义

表示可以包含整数的向量部分。

C#
public struct BitVector32.Section
C#
public readonly struct BitVector32.Section
C#
public readonly struct BitVector32.Section : IEquatable<System.Collections.Specialized.BitVector32.Section>
继承
BitVector32.Section
实现

示例

下面的代码示例使用 BitVector32 作为节的集合。

C#
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

*/

注解

使用 CreateSection 定义新节。 是 BitVector32.Section 进入 BitVector32 的窗口,由可包含 中指定的 CreateSection最大值的最小连续位数组成。 例如,最大值为 1 的节仅由 1 位组成,而最大值为 5 的节由 3 位组成。 可以创建 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 对象是否具有不同的值。

适用于

产品 版本
.NET Core 1.0, Core 1.1, Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 2.0, 2.1
UWP 10.0

另请参阅