次の方法で共有


BitArray.SetAll メソッド

BitArray 内のすべてのビットを指定した値に設定します。

Public Sub SetAll( _
   ByVal value As Boolean _)
[C#]
public void SetAll(boolvalue);
[C++]
public: void SetAll(boolvalue);
[JScript]
public function SetAll(
   value : Boolean);

パラメータ

  • value
    すべてのビットに代入するブール値。

使用例

[Visual Basic, C#, C++] BitArray 内の特定の要素を設定および取得する方法の例を次に示します。

 
Imports System
Imports System.Collections
Imports Microsoft.VisualBasic

Public Class SamplesBitArray    
    
    Public Shared Sub Main()
        
        ' Creates and initializes a BitArray.
        Dim myBA As New BitArray(5)
        
        ' Displays the properties and values of the BitArray.
        Console.WriteLine("myBA values:")
        PrintIndexAndValues(myBA)
        
        ' Sets all the elements to true.
        myBA.SetAll(True)
        
        ' Displays the properties and values of the BitArray.
        Console.WriteLine("After setting all elements to true,")
        PrintIndexAndValues(myBA)
        
        ' Sets the last index to false.
        myBA.Set(myBA.Count - 1, False)
        
        ' Displays the properties and values of the BitArray.
        Console.WriteLine("After setting the last element to false,")
        PrintIndexAndValues(myBA)
        
        ' Gets the value of the last two elements.
        Console.WriteLine("The last two elements are: ")
        Console.WriteLine(ControlChars.Tab + "at index {0} : {1}", _
           myBA.Count - 2, myBA.Get(myBA.Count - 2))
        Console.WriteLine(ControlChars.Tab + "at index {0} : {1}", _
           myBA.Count - 1, myBA.Get(myBA.Count - 1))
    End Sub 'Main
    
    
    
    Public Shared Sub PrintIndexAndValues(myList As IEnumerable)
        Dim i As Integer = 0
        Dim myEnumerator As System.Collections.IEnumerator = _
           myList.GetEnumerator()
        While myEnumerator.MoveNext()
            Console.WriteLine(ControlChars.Tab + "[{0}]:" + ControlChars.Tab _
               + "{1}", i, myEnumerator.Current)
            i += 1
        End While
        Console.WriteLine()
    End Sub
End Class

' This code produces the following output.
' 
' myBA values:
'     [0]:    False
'     [1]:    False
'     [2]:    False
'     [3]:    False
'     [4]:    False
' 
' After setting all elements to true,
'     [0]:    True
'     [1]:    True
'     [2]:    True
'     [3]:    True
'     [4]:    True
' 
' After setting the last element to false,
'     [0]:    True
'     [1]:    True
'     [2]:    True
'     [3]:    True
'     [4]:    False
' 
' The last two elements are: 
'     at index 3 : True
'     at index 4 : False 

[C#] 
using System;
using System.Collections;
public class SamplesBitArray  {

   public static void Main()  {

      // Creates and initializes a BitArray.
      BitArray myBA = new BitArray( 5 );

      // Displays the properties and values of the BitArray.
      Console.WriteLine( "myBA values:" );
      PrintIndexAndValues( myBA );

      // Sets all the elements to true.
      myBA.SetAll( true );

      // Displays the properties and values of the BitArray.
      Console.WriteLine( "After setting all elements to true," );
      PrintIndexAndValues( myBA );

      // Sets the last index to false.
      myBA.Set( myBA.Count - 1, false );

      // Displays the properties and values of the BitArray.
      Console.WriteLine( "After setting the last element to false," );
      PrintIndexAndValues( myBA );

      // Gets the value of the last two elements.
      Console.WriteLine( "The last two elements are: " );
      Console.WriteLine( "\tat index {0} : {1}", myBA.Count - 2, myBA.Get( myBA.Count - 2 ) );
      Console.WriteLine( "\tat index {0} : {1}", myBA.Count - 1, myBA.Get( myBA.Count - 1 ) );
   }


   public static void PrintIndexAndValues( IEnumerable myList )  {
      int i = 0;
      System.Collections.IEnumerator myEnumerator = myList.GetEnumerator();
      while ( myEnumerator.MoveNext() )
         Console.WriteLine( "\t[{0}]:\t{1}", i++, myEnumerator.Current );
      Console.WriteLine();
   }
}
/* 
This code produces the following output.

myBA values:
    [0]:    False
    [1]:    False
    [2]:    False
    [3]:    False
    [4]:    False

After setting all elements to true,
    [0]:    True
    [1]:    True
    [2]:    True
    [3]:    True
    [4]:    True

After setting the last element to false,
    [0]:    True
    [1]:    True
    [2]:    True
    [3]:    True
    [4]:    False

The last two elements are: 
    at index 3 : True
    at index 4 : False
*/ 

[C++] 
#using <mscorlib.dll>
#using <system.dll>

using namespace System;
using namespace System::Collections;

void PrintIndexAndValues( IEnumerable* myList )  {
   int i = 0;
   System::Collections::IEnumerator* myEnumerator = myList->GetEnumerator();
   while ( myEnumerator->MoveNext() )
      Console::WriteLine( S"\t[{0}]:\t{1}", __box(i++), myEnumerator->Current );
   Console::WriteLine();
}

int main()  {
   // Creates and initializes a BitArray.
   BitArray* myBA = new BitArray( 5 );

   // Displays the properties and values of the BitArray.
   Console::WriteLine( S"myBA values:" );
   PrintIndexAndValues( myBA );

   // Sets all the elements to true.
   myBA->SetAll( true );

   // Displays the properties and values of the BitArray.
   Console::WriteLine( S"After setting all elements to true," );
   PrintIndexAndValues( myBA );

   // Sets the last index to false.
   myBA->Set( myBA->Count - 1, false );

   // Displays the properties and values of the BitArray.
   Console::WriteLine( S"After setting the last element to false," );
   PrintIndexAndValues( myBA );

   // Gets the value of the last two elements.
   Console::WriteLine( S"The last two elements are: " );
   Console::WriteLine( S"\tat index {0} : {1}", __box(myBA->Count - 2), __box(myBA->Get( myBA->Count - 2 )) );
   Console::WriteLine( S"\tat index {0} : {1}", __box(myBA->Count - 1), __box(myBA->Get( myBA->Count - 1 )) );
}
/*
This code produces the following output.

myBA values:
        [0]:    False
        [1]:    False
        [2]:    False
        [3]:    False
        [4]:    False

After setting all elements to true,
        [0]:    True
        [1]:    True
        [2]:    True
        [3]:    True
        [4]:    True

After setting the last element to false,
        [0]:    True
        [1]:    True
        [2]:    True
        [3]:    True
        [4]:    False

The last two elements are:
        at index 3 : True
        at index 4 : False
*/

[JScript] JScript のサンプルはありません。Visual Basic、C#、および C++ のサンプルを表示するには、このページの左上隅にある言語のフィルタ ボタン 言語のフィルタ をクリックします。

必要条件

プラットフォーム: 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

参照

BitArray クラス | BitArray メンバ | System.Collections 名前空間