[Solved] Queue of Arrays in C# [closed]


This is actually pretty easy. A queue of ints is no different than a queue of any other type, really. You could just as easily have a queue of lists or a queue of queues or anything like that.

I’m using the queue constructor that accepts an IEnumerable to initialize these by the way. In the first case, I’m building a queue from an array of arrays of ints.

In the second case, I’m building a queue from an array of ints. I show that as an example because it’s unclear from your post that you actually need a queue of arrays. If every queue just contains four ints, why not just create queues with 4 ints in them? Why bother with the whole queue of arrays thing?

Either way, here’s teh codez:

        // Here you have it - a queue of arrays
        // Really, it's no different than a queue of any other type
        Queue<int[]> queue = new Queue<int[]>(
            // Construct the queue from the following array of arrays
            new[]
            {
                new[] { 3, 2, 1, 0 },
                new[] { 32, 24, 234, 3 }
                // Whatever you want
            }
        );

        // If all you want is a queue with four ints, why bother with the queue of array thing?
        // You can initialize a queue with some numbers like this
        Queue<int> queueOfInts = new Queue<int>(new[] { 3, 2, 1, 0 });

1

solved Queue of Arrays in C# [closed]