[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 416
  • Last Modified:

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

0
mrmox
Asked:
mrmox
2 Solutions
 
dj_alikCommented:
1.   public Queue<double>[] queues = new  Queue<double>[2];

2. Queue.Synchronized Method
http://msdn.microsoft.com/en-us/library/system.collections.queue.synchronized.aspx 
0
 
wdosanjosCommented:
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.
0
 
wdosanjosCommented:
BTW, regarding @dj_alik solution, you also need to initialize it as follows:

public Queue<double>[] queues = new Queue<double>[10];

for (int i=0; i < queues.Length; i++) queues[i] = new Queue();  // in your constructor

Open in new window

0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
anarki_jimbelCommented:
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.

0
 
wdosanjosCommented:
@anarki_jimbel, you are right. Sorry, for the misinformation.
0
 
mrmoxAuthor Commented:
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.
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now