BitVector32.Section 構造体
整数を格納できるベクタのセクションを表します。
この型のすべてのメンバの一覧については、BitVector32.Section メンバ を参照してください。
System.Object
System.ValueType
System.Collections.Specialized.BitVector32.Section
Public Structure BitVector32.Section
[C#]
public struct BitVector32.Section
[C++]
public __value struct BitVector32.Section
[JScript] JScript では、.NET Framework の構造体を利用することができます。ただし、独自に定義することはできません。
スレッドセーフ
この型の public static (Visual Basicでは Shared) のすべてのメンバは、マルチスレッド操作で安全に使用できます。インスタンスのメンバの場合は、スレッドセーフであるとは限りません。
解説
CreateSection を使用して新しいセクションを定義します。 BitVector32.Section は BitVector32 内のウィンドウで、 CreateSection で指定した最大値を格納できる最小数の連続ビットから構成されます。たとえば、最大値が 1 のセクションは 1 ビットだけで構成され、最大値が 5 のセクションは 3 ビットで構成されます。ブール値として機能する最大値 1 で BitVector32.Section を作成して、同じ BitVector32 に整数とブール値を格納できます。
使用例
[Visual Basic, C#, C++] 次のコード例では、 BitVector32 をセクションのコレクションとして使用しています。
Imports System
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 'Main
End Class 'SamplesBitVector32
' 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
[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
*/
[C++]
#using <mscorlib.dll>
#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(S"Initial values:");
Console::WriteLine(S"\tmySect1: {0}", __box(myBV.Item[mySect1]));
Console::WriteLine(S"\tmySect2: {0}", __box(myBV.Item[mySect2]));
Console::WriteLine(S"\tmySect3: {0}", __box(myBV.Item[mySect3]));
Console::WriteLine(S"\tmySect4: {0}", __box(myBV.Item[mySect4]));
// Sets each section to a new value and displays the value of the BitVector32 at each step.
Console::WriteLine(S"Changing the values of each section:");
Console::WriteLine(S"\tInitial: \t {0}", __box(myBV));
myBV.Item[mySect1] = 5;
Console::WriteLine(S"\tmySect1 = 5:\t {0}", __box(myBV));
myBV.Item[mySect2] = 3;
Console::WriteLine(S"\tmySect2 = 3:\t {0}", __box(myBV));
myBV.Item[mySect3] = 1;
Console::WriteLine(S"\tmySect3 = 1:\t {0}", __box(myBV));
myBV.Item[mySect4] = 9;
Console::WriteLine(S"\tmySect4 = 9:\t {0}", __box(myBV));
// Displays the values of the sections.
Console::WriteLine(S"New values:");
Console::WriteLine(S"\tmySect1: {0}", __box(myBV.Item[mySect1]));
Console::WriteLine(S"\tmySect2: {0}", __box(myBV.Item[mySect2]));
Console::WriteLine(S"\tmySect3: {0}", __box(myBV.Item[mySect3]));
Console::WriteLine(S"\tmySect4: {0}", __box(myBV.Item[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
*/
[JScript] JScript のサンプルはありません。Visual Basic、C#、および C++ のサンプルを表示するには、このページの左上隅にある言語のフィルタ ボタン をクリックします。
必要条件
名前空間: System.Collections.Specialized
プラットフォーム: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 ファミリ, .NET Compact Framework - Windows CE .NET
アセンブリ: System (System.dll 内)
参照
BitVector32.Section メンバ | System.Collections.Specialized 名前空間 | BitVector32.CreateSection