BitVector32.CreateSection 方法  
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
创建包含小整数的一系列节。
重载
| CreateSection(Int16) | 创建一系列包含小整数的节中的第一个 BitVector32.Section。 | 
| CreateSection(Int16, BitVector32+Section) | 在一系列包含小整数的节中,在指定的 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(Int16)
- Source:
- BitVector32.cs
- Source:
- BitVector32.cs
- Source:
- BitVector32.cs
创建一系列包含小整数的节中的第一个 BitVector32.Section。
public:
 static System::Collections::Specialized::BitVector32::Section CreateSection(short maxValue);public static System.Collections.Specialized.BitVector32.Section CreateSection (short maxValue);static member CreateSection : int16 -> System.Collections.Specialized.BitVector32.SectionPublic Shared Function CreateSection (maxValue As Short) As BitVector32.Section参数
- maxValue
- Int16
一个 16 位有符号整数,它为新 BitVector32.Section 指定最大值。
返回
一个 BitVector32.Section,它可以保存从零到 maxValue 的数字。
例外
              maxValue 小于 1。
注解
是 BitVector32.Section 进入 BitVector32 的窗口,由可包含 中指定的 CreateSection最大值的最小连续位数组成。 例如,最大值为 1 的节仅由 1 位组成,而最大值为 5 的节由 3 位组成。 可以创建 BitVector32.Section 最大值为 1 的 以用作布尔值,从而允许在同 BitVector32一 个 中存储整数和布尔值。
如果 中 BitVector32已存在部分,则仍可访问这些部分;但是,重叠部分可能会导致意外结果。
此方法是 O (1) 操作。
适用于
CreateSection(Int16, BitVector32+Section)
- Source:
- BitVector32.cs
- Source:
- BitVector32.cs
- Source:
- BitVector32.cs
在一系列包含小整数的节中,在指定的 BitVector32.Section 后面创建新的 BitVector32.Section。
public:
 static System::Collections::Specialized::BitVector32::Section CreateSection(short maxValue, System::Collections::Specialized::BitVector32::Section previous);public static System.Collections.Specialized.BitVector32.Section CreateSection (short maxValue, System.Collections.Specialized.BitVector32.Section previous);static member CreateSection : int16 * System.Collections.Specialized.BitVector32.Section -> System.Collections.Specialized.BitVector32.SectionPublic Shared Function CreateSection (maxValue As Short, previous As BitVector32.Section) As BitVector32.Section参数
- maxValue
- Int16
一个 16 位有符号整数,它为新 BitVector32.Section 指定最大值。
- previous
- BitVector32.Section
BitVector32.Section 中的前一个 BitVector32。
返回
一个 BitVector32.Section,它可以保存从零到 maxValue 的数字。
例外
              maxValue 小于 1。
注解
是 BitVector32.Section 进入 BitVector32 的窗口,由可包含 中指定的 CreateSection最大值的最小连续位数组成。 例如,最大值为 1 的节仅由 1 位组成,而最大值为 5 的节由 3 位组成。 可以创建 BitVector32.Section 最大值为 1 的 以用作布尔值,从而允许在同 BitVector32一 个 中存储整数和布尔值。
如果 之后已存在 previous 部分, BitVector32则仍可访问这些部分;但是,重叠部分可能会导致意外结果。
此方法是 O (1) 操作。