固定长度 BitArray 数组
我遇到了 BitArray
的麻烦。
目标是模拟 8 个 80 位 BitArray 的堆栈,编号从 0 到 7。
我只需要能够通过索引访问它们,所以我认为一个简单的数组对我来说就足够了。
初始化 BitArray
对象时,我需要指定它将包含的位数,这给了我
BitArray test = new BitArray(80);
如何在知道我需要指定长度值的情况下创建它的数组?
我已经尝试了几件事,例如
BitArray[] stack = new BitArray(80)[];
,但在尝试给出长度时我总是遇到错误......
有什么想法吗?
提前致谢
I'm in trouble with a BitArray
.
The goal is to simulate a stack of 8 80bit BitArrays, numbered from 0 to 7.
I just need to be able to access them by index, and so I think a simple array will be enough for me.
When initialising a BitArray
object, I need to specify the number of bits it will contain, which gives me
BitArray test = new BitArray(80);
How can I do an Array of it, knowing I need to specify the length value?
I've tried several things, like
BitArray[] stack = new BitArray(80)[];
but I always get an error when trying to give it the length...
Any thoughts?
Thanks in advance
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
不幸的是,据我所知,该框架似乎没有“规范的”数组初始化模式。
使用 LINQ 的一种方法是:
或:
或者,
Unfortunately, the framework doesn't appear to have a "canonical" array-initialization pattern, as far as I know.
One way, using LINQ, would be:
or:
Alternatively,
首先像这样创建 BitArray 数组 ([]):
然后在 for 循环中初始化所有单独的位数组(类似这样):
编辑: 这样的东西或多或少是一个指针,而不是实际测试过;下面是:
First create your BitArray array ([]) like this:
and then initialize all seperate bitarrays in a for-loop (something like this):
Edit: the something like this was more or less a pointer, not actually tested; this below is:
好吧...
我终于这样做了:
感谢您的回答,这使我找到了这个解决方案,这似乎对我有用。
祝您有美好的一天,再次感谢!
Well...
I finally did it this way:
Thanks for your answers, which leaded me to this solution, wich seems to work for me.
Have a nice day, and again, thanks!