
- C# Basic Tutorial
- C# - Home
- C# - Overview
- C# - Environment
- C# - Program Structure
- C# - Basic Syntax
- C# - Data Types
- C# - Type Conversion
- C# - Variables
- C# - Constants
- C# - Operators
- C# - Decision Making
- C# - Loops
- C# - Encapsulation
- C# - Methods
- C# - Nullables
- C# - Arrays
- C# - Strings
- C# - Structure
- C# - Enums
- C# - Classes
- C# - Inheritance
- C# - Polymorphism
- C# - Operator Overloading
- C# - Interfaces
- C# - Namespaces
- C# - Preprocessor Directives
- C# - Regular Expressions
- C# - Exception Handling
- C# - File I/O
- C# Advanced Tutorial
- C# - Attributes
- C# - Reflection
- C# - Properties
- C# - Indexers
- C# - Delegates
- C# - Events
- C# - Collections
- C# - Generics
- C# - Anonymous Methods
- C# - Unsafe Codes
- C# - Multithreading
- C# Useful Resources
- C# - Questions and Answers
- C# - Quick Guide
- C# - Useful Resources
- C# - Discussion
Set all bits in the BitArray to the specified value in C#
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("
Updated 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("
Updated 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
- Related Articles
- Set the bit at a specific position in the BitArray to the specified value in C#?
- Get or set the number of elements in the BitArray in C#
- Get or set the value associated with the specified key in StringDictionary in C#
- Get or Set the value associated with specified key in Hashtable in C#
- Get or set the value associated with specified key in ListDictionary in C#
- Get or set the value associated with specified key in SortedList in C#
- How to set a value to the element at the specified position in the one-dimensional array in C#
- Check if all bits of a number are set in Python
- Python program to count total set bits in all number from 1 to n.
- Golang Program to count the set bits in an integer.
- XOR of all elements of array with set bits equal to K in C++
- C/C++ Program to the Count set bits in an integer?
- Get value of the bit at a specific position in BitArray in C#
- Program to count total number of set bits of all numbers in range 0 to n in Python
- Print numbers having first and last bits as the only set bits

Advertisements