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
Enumerator that iterates through the BitArray in C#
Following is the code that iterates through the BitArray with Enumerator −
Example
using System;
using System.Collections;
public class Demo {
public static void Main(){
BitArray arr1 = new BitArray(5);
BitArray arr2 = new BitArray(5);
arr1[0] = false;
arr1[1] = true;
arr1[2] = false;
arr1[3] = true;
arr1[4] = true;
Console.WriteLine("Enumerator that iterates through BitArray1");
IEnumerable demoEnum = arr1;
foreach(Object ob in demoEnum){
Console.WriteLine(ob);
}
arr2[0] = true;
arr2[1] = true;
arr2[2] = true;
arr2[3] = false;
arr2[4] = true;
Console.WriteLine("Enumerator that iterates through BitArray2");
demoEnum = arr2;
foreach(Object ob in demoEnum){
Console.WriteLine(ob);
}
Console.WriteLine("Is BitArray1 equal to BitArray2? = "+arr1.Equals(arr2));
}
}
Output
This will produce the following output −
Enumerator that iterates through BitArray1 False True False True True Enumerator that iterates through BitArray2 True True True False True Is BitArray1 equal to BitArray2? = 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] = false;
arr[1] = true;
arr[2] = false;
arr[3] = true;
arr[4] = true;
Console.WriteLine("Enumerator that iterates through BitArray");
IEnumerable demoEnum = arr;
foreach(Object ob in demoEnum){
Console.WriteLine(ob);
}
}
}
Output
This will produce the following output −
Enumerator that iterates through BitArray False True False True True
Advertisements