Fixed Bitrate Array

I have problems with BitArray.

The goal is to simulate a stack of 8 80 BitArrays bits, numbered 0 through 7.

I just need to have access to them by index, so I think a simple array will be enough for me.

When initializing an object, BitArrayI need to specify the number of bits it will contain, which gives me

BitArray test = new BitArray(80);

How can I make an array of this, knowing that I need to specify a length value?

I tried several things, for example

BitArray[] stack = new BitArray(80)[];

but I always get an error when trying to give it a length ...

Any thoughts?

Thanks in advance

+3
source share
3 answers

Well...

, , :

List<BitArray> stack = new List<BitArray>(8);

public FPU()
{
    //initialise the stack

    for (int i = 0; i < stack.Capacity; i++)
    {
        stack[i] = new BitArray(80);
    }
}

, , , , .

, , !

-1

, , -, , .

, LINQ, :

var stack = Enumerable.Range(0, 8)
                      .Select(i => new BitArray(80))
                      .ToArray();

var stack = Enumerable.Repeat<Func<BitArray>>( () => new BitArray(80), 8)
                      .Select(f => f())
                      .ToArray();

BitArray[] stack = new BitArray[8];

for(int i = 0; i < stack.Length; i++)
   stack[i] = new BitArray(80);
+4

First create an array of BitArray ([]) as follows:

BitArray[] stack = new BitArray[8];

and then initialize all the individual bitrates in a for-loop (something like this):

foreach (BitArray arr in stack)
{
    arr = new BitArray(80);
}

Edit: something like this was more or less a pointer, not checked; it is below:

BitArray[] stack = new BitArray[8];
for(int i=0;i<stack.Length;i++)
{
    stack[i] = new BitArray(80);
}
stack[0][0] = true;
+2
source

Source: https://habr.com/ru/post/1777864/


All Articles