
- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
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
Number of elements contained in the BitArray in C#?
To get the number of elements contained 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(5); BitArray arr2 = new BitArray(5); arr1[0] = false; arr1[1] = false; arr2[0] = false; arr2[1] = true; Console.WriteLine("BitArray1 elements..."); foreach (bool res in arr1) { Console.WriteLine(res); } Console.WriteLine("\nBitArray2 elements..."); foreach (bool res in arr2) { Console.WriteLine(res); } Console.WriteLine("\nBitwise OR operation..."); IEnumerable demoEnum = arr1.Or(arr2); foreach(Object ob in demoEnum) { Console.WriteLine(ob); } Console.WriteLine("\nNumber of elements in the resultant BitArray = "+arr1.Count); } }
Output
This will produce the following output −
BitArray1 elements... False False False False False BitArray2 elements... False True False False False Bitwise OR operation... False True False False False Number of elements in the resultany BitArray = 5
Example
Let us now see another example −
using System; using System.Collections; public class Demo { public static void Main() { BitArray arr = new BitArray(2); arr[0] = false; arr[1] = true; Console.WriteLine("Elements in BitArray..."); foreach (bool res in arr) { Console.WriteLine(res); } Console.WriteLine("\nNumber of elements in the BitArray = "+arr.Count); bool[] boolArr = new bool[2]; boolArr[0] = true; boolArr[1] = false; arr.CopyTo(boolArr, 0); Console.WriteLine("\nArray..."); foreach(Object obj in boolArr) { Console.WriteLine(obj); } } }
Output
This will produce the following output −
Elements in BitArray... False True Number of elements in the BitArray = 2 Array... False True
- Related Questions & Answers
- Get the number of elements contained in Collection in C#
- Get the number of elements contained in SortedList in C#
- Get the number of elements contained in the Queue in C#
- Get the number of elements contained in the Stack in C#
- Get or set the number of elements in the BitArray in C#
- Get the number of elements actually contained in the ArrayList in C#
- Bitwise OR operation between the elements of BitArray in C#
- Get the number of nodes contained in LinkedList in C#
- Bitwise exclusive OR operation between the elements of BitArray in C#
- Copying BitArray elements to an Array in C#
- Get the number of key/values pairs contained in OrderedDictionary in C#
- Get the number of key/value pairs contained in ListDictionary in C#
- BitArray Class in C#
- Contained Interval in C++
- What is the BitArray class in C#?
Advertisements