- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
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
Advertisements