Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- 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 the bit at a specific position in the BitArray to the specified value in C#?
To set the bit a specific position in the BitArray to the specified values, 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] = true;
arr[1] = false;
arr[2] = true;
arr[3] = false;
Console.WriteLine("BitArray...");
foreach(Object ob in arr) {
Console.WriteLine(ob);
}
arr.Set(2, 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... True False False False False
Example
Let us now 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.Set(0, false);
arr.Set(1, true);
arr.Set(2, 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 True False False False
Advertisements