BitVector32.CreateSection Méthode
Définition
Important
Certaines informations portent sur la préversion du produit qui est susceptible d’être en grande partie modifiée avant sa publication. Microsoft exclut toute garantie, expresse ou implicite, concernant les informations fournies ici.
Crée une série de sections qui contiennent de petits entiers.
Surcharges
| Nom | Description |
|---|---|
| CreateSection(Int16) |
Crée la première BitVector32.Section dans une série de sections qui contiennent de petits entiers. |
| CreateSection(Int16, BitVector32+Section) |
Crée une nouvelle BitVector32.Section valeur suivante BitVector32.Section dans une série de sections qui contiennent de petits entiers. |
Exemples
L’exemple de code suivant utilise une BitVector32 collection de sections.
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)
Crée la première BitVector32.Section dans une série de sections qui contiennent de petits entiers.
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.Section
Public Shared Function CreateSection (maxValue As Short) As BitVector32.Section
Paramètres
- maxValue
- Int16
Entier signé 16 bits qui spécifie la valeur maximale pour le nouveau BitVector32.Section.
Retours
Qui BitVector32.Section peut contenir un nombre compris entre zéro et maxValue.
Exceptions
maxValue est inférieur à 1.
Remarques
A BitVector32.Section est une fenêtre dans le BitVector32 et se compose du plus petit nombre de bits consécutifs qui peuvent contenir la valeur maximale spécifiée dans CreateSection. Par exemple, une section avec une valeur maximale de 1 est composée d’un seul bit, tandis qu’une section avec une valeur maximale de 5 est composée de trois bits. Vous pouvez créer une BitVector32.Section valeur maximale de 1 pour servir de booléen, ce qui vous permet de stocker des entiers et des booléens dans le même BitVector32.
Si des sections existent déjà dans le BitVector32, ces sections sont toujours accessibles ; toutefois, les sections qui se chevauchent peuvent entraîner des résultats inattendus.
Cette méthode est une opération O(1).
S’applique à
CreateSection(Int16, BitVector32+Section)
Crée une nouvelle BitVector32.Section valeur suivante BitVector32.Section dans une série de sections qui contiennent de petits entiers.
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.Section
Public Shared Function CreateSection (maxValue As Short, previous As BitVector32.Section) As BitVector32.Section
Paramètres
- maxValue
- Int16
Entier signé 16 bits qui spécifie la valeur maximale pour le nouveau BitVector32.Section.
- previous
- BitVector32.Section
BitVector32.Section Précédent dans le BitVector32.
Retours
Qui BitVector32.Section peut contenir un nombre compris entre zéro et maxValue.
Exceptions
maxValue est inférieur à 1.
previous inclut le bit final dans le BitVector32.
-ou-
maxValue est supérieur à la valeur la plus élevée qui peut être représentée par le nombre de bits après previous.
Remarques
A BitVector32.Section est une fenêtre dans le BitVector32 et se compose du plus petit nombre de bits consécutifs qui peuvent contenir la valeur maximale spécifiée dans CreateSection. Par exemple, une section avec une valeur maximale de 1 est composée d’un seul bit, tandis qu’une section avec une valeur maximale de 5 est composée de trois bits. Vous pouvez créer une BitVector32.Section valeur maximale de 1 pour servir de booléen, ce qui vous permet de stocker des entiers et des booléens dans le même BitVector32.
Si des sections existent déjà après previous , BitVector32ces sections sont toujours accessibles . Toutefois, les sections qui se chevauchent peuvent entraîner des résultats inattendus.
Cette méthode est une opération O(1).