[英]BitArray doesn't work as expected
I have this BitArray : 我有这个BitArray:
BitArray bits = new BitArray(2);
bits[0] = false;
bits[1] = true;
Which represents : 10b
--> 2 代表: 10b
> 2
Let's see what's its value : 让我们看看它的价值是什么:
int[] array = new int[1];
bits.CopyTo(array, 0);
Console.WriteLine(array[0]); // value=2
Great. 大。
Now I'm changing the first code to : 现在,我将第一个代码更改为:
bool[] bits = new bool[2] { false, true }; //same value !
BitArray myBA4 = new BitArray( bits );
//and again...
int[] array = new int[1];
bits.CopyTo(array, 0);
Console.WriteLine(array[0]);
Question 题
Where is my mistake ? 我的错误在哪里? I think it should be same result. 我认为应该是相同的结果。
bool[] bits = new bool[2] { false, true };
allocates an array of two elements, and CopyTo
is supposed to copy them one by one. 分配两个元素组成的数组, CopyTo
应该一个一个地复制它们。 It cannot succeed because 它不能成功,因为
bool
cannot be converted to int
implicitly. bool
不能隐式转换为int
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.