C# 中 BitArray 中元素之間的按位 OR 運算


接下來,讓我們看看如何在 BitArray 元素之間進行按位 OR 運算 −

示例

 線上示例

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("
BitArray2 elements...");       foreach (bool res in arr2) {          Console.WriteLine(res);       }       Console.WriteLine("
Bitwise OR operation...");       IEnumerable demoEnum = arr1.Or(arr2);       foreach(Object ob in demoEnum) {          Console.WriteLine(ob);       }    } }

輸出

輸出如下 −

BitArray1 elements...
False
False
False
False
False
BitArray2 elements...
False
True
False
False
False
Bitwise OR operation...
False
True
False
False
False

更新於: 10-Dec-2019

56 瀏覽

開啟您的 職業生涯

完成課程即獲得認證

開始
廣告