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
Get or set the number of elements in the BitArray in C#
To get or set the number of elements in the BitArray, the code is as follows −
Example
using System;
using System.Collections;
public class Demo {
public static void Main() {
BitArray arr1 = new BitArray(2);
BitArray arr2 = new BitArray(2);
arr1[0] = false;
arr1[1] = true;
Console.WriteLine("BitArray1 length = "+arr1.Length);
Console.WriteLine("Elements in BitArray1...");
foreach (bool res in arr1) {
Console.WriteLine(res);
}
arr2[0] = false;
arr2[1] = true;
Console.WriteLine("
BitArray2 length = "+arr2.Length);
Console.WriteLine("Elements in BitArray2...");
foreach (bool res in arr2) {
Console.WriteLine(res);
}
Console.WriteLine("
Is BitArray1 equal to BitArray2? = "+arr2.Equals(arr1));
}
}
Output
This will produce the following output −
BitArray1 length = 2 Elements in BitArray1... False True BitArray2 length = 2 Elements in BitArray2... False True Is BitArray1 equal to BitArray2? = False
Example
Let us see another example −
using System;
using System.Collections;
public class Demo {
public static void Main() {
BitArray arr1 = new BitArray(2);
BitArray arr2 = new BitArray(1);
arr1[0] = false;
arr1[1] = true;
Console.WriteLine("BitArray1 length = "+arr1.Length);
Console.WriteLine("Elements in BitArray1...");
foreach (bool res in arr1) {
Console.WriteLine(res);
}
Console.WriteLine("
BitArray2 length = "+arr2.Length);
Console.WriteLine("Elements in BitArray2...");
foreach (bool res in arr2) {
Console.WriteLine(res);
}
}
}
Output
This will produce the following output −
BitArray1 length = 2 Elements in BitArray1... False True BitArray2 length = 1 Elements in BitArray2... False
Advertisements