
- 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 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
- Related Articles
- Get value of the bit at a specific position in BitArray in C#
- Gets or sets the value of the bit at a specific position in the BitArray in C#
- Set all bits in the BitArray to the specified value in C#
- How to set a value to the element at the specified position in the one-dimensional array in C#
- Find position of the only set bit in C++
- Set characters at a specific position within the string in Arduino
- Position of the K-th set bit in a number in C++
- Position of rightmost set bit in C++
- Insert the specified element at the specified position in Java CopyOnWriteArrayList
- Check whether the bit at given position is set or unset in Python
- Convert the value of the specified Decimal to the equivalent 16-bit unsigned integer in C#
- Inverting all bit values in BitArray in C#
- Golang Program to find the position of the rightmost set bit
- The listIterator() method AbstractList class in Java at a specified position
- Getting the value at the specified index of a SortedList object in C#

Advertisements