0

I have a string value that consists of 1s and 0s. value "1" is set if the checkbox is checked and "0" if not checked. Example:

 string CheckedVal = "11100110111";

Now I need to convert [CheckedVal] to BitArray() in order send it thorugh a relay thread.

Is there a way to convert the string [CheckedVal] to BitArray()?

Dmitry Bychenko
  • 180,369
  • 20
  • 160
  • 215
jean chu
  • 145
  • 4
  • 13

1 Answers1

2

Try using Linq: we turn initial string into array - bool[] and then create BitArray as usual:

  using System.Linq;

  ...

  string CheckedVal = "11100110111";

  BitArray result = new BitArray(CheckedVal.Select(c => c == '1').ToArray());
Dmitry Bychenko
  • 180,369
  • 20
  • 160
  • 215