Link to home
Start Free TrialLog in
Avatar of mrmox
mrmox

asked on

C# syntax for array of Queue

I cannot find syntax for arrays of Queue!  All variations I have tried
seem to be rejected by the compiler in VS2008.
Perhaps someone can give me an answer to this?
Currently I have made the Queues separate as shown below:

        // this form does not seem to accept an argument for initial capacity!
        public Queue<double> firstQueue0 = new Queue<double>();
        public Queue<double> firstQueue1 = new Queue<double>();
        public Queue<double> firstQueue2 = new Queue<double>();
        public Queue<double> firstQueue3 = new Queue<double>();
        public Queue<double> firstQueue4 = new Queue<double>();
        public Queue<double> firstQueue5 = new Queue<double>();
        public Queue<double> firstQueue6 = new Queue<double>();
        public Queue<double> firstQueue7 = new Queue<double>();
        public Queue<double> firstQueue8 = new Queue<double>();
        public Queue<double> firstQueue9 = new Queue<double>();

THis works for me but what I would really like is an array.

Also is Queue threadsafe?

And why does  Queue<double>() not accept an initial capacity
argument like         Queue firstQueue0 = new Queue(100); does?

Thanks!

- mrmox

ASKER CERTIFIED SOLUTION
Avatar of dj_alik
dj_alik

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
The Queue constructor with a initial capacity parameter is only available on .NET Framework 4.  Prior versions of the framework does not have that option.
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Dmitry G
OK, I believe wdosanjos gives wrong information. See
 http://msdn.microsoft.com/en-us/library/system.collections.queue.queue(v=VS.80).aspx
for the 2.0Queue class:

"Queue (Int32)       Initializes a new instance of the Queue class that is empty, has the specified initial capacity, and uses the default growth factor."

About arrays. I believe the asker has VB experience and tried to create an array using "()" brackets instead of "[]". I do this mistake quite often when switching from VB to C#...

dj_alik answered about thread safety.

@anarki_jimbel, you are right. Sorry, for the misinformation.
Avatar of mrmox
mrmox

ASKER

Thank you, I am now able to instantiate an array of queues.
Some of my confusion may have been in thinking
I should be able to instantiate the array and
populate it with queue objects in one step/line.
So, the part from @wdosanjos was useful to me.
I would still like to understand why Queue<double>
and Queue come from different places but I did not ask
that specifically I realize.