To set all bits in the BitArray to the specified value, the code is as follows −
Example
using System;
using System.Collections;
public class Demo {
public static void Main() {
BitArray arr = new BitArray(5);
arr[0] = false;
arr[1] = false;
arr[2] = false;
arr[3] = false;
Console.WriteLine("BitArray...");
foreach(Object ob in arr) {
Console.WriteLine(ob);
}
arr.SetAll(true);
Console.WriteLine("\nUpdated BitArray...");
foreach(Object ob in arr) {
Console.WriteLine(ob);
}
}
}Output
This will produce the following output −
BitArray... False False False False False Updated BitArray... True True True True True
Example
Let us see another example −
using System;
using System.Collections;
public class Demo {
public static void Main() {
BitArray arr = new BitArray(5);
arr[0] = true;
arr[1] = false;
arr[2] = true;
arr[3] = false;
Console.WriteLine("BitArray...");
foreach(Object ob in arr) {
Console.WriteLine(ob);
}
arr.SetAll(false);
Console.WriteLine("\nUpdated BitArray...");
foreach(Object ob in arr) {
Console.WriteLine(ob);
}
}
}Output
This will produce the following output −
BitArray... True False True False False Updated BitArray... False False False False False