C# syntax for array of Queue

Posted on 2011-05-09
Last Modified: 2012-05-11
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?


- mrmox

Question by:mrmox
    LVL 18

    Accepted Solution

    1.   public Queue<double>[] queues = new  Queue<double>[2];

    2. Queue.Synchronized Method
    LVL 23

    Expert Comment

    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.
    LVL 23

    Assisted Solution

    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

    LVL 29

    Expert Comment

    OK, I believe wdosanjos gives wrong information. See
    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.

    LVL 23

    Expert Comment

    @anarki_jimbel, you are right. Sorry, for the misinformation.

    Author Closing Comment

    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.

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    What Should I Do With This Threat Intelligence?

    Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

    Extention Methods in C# 3.0 by Ivo Stoykov C# 3.0 offers extension methods. They allow extending existing classes without changing the class's source code or relying on inheritance. These are static methods invoked as instance method. This…
    Introduction Although it is an old technology, serial ports are still being used by many hardware manufacturers. If you develop applications in C#, Microsoft .NET framework has SerialPort class to communicate with the serial ports.  I needed to…
    This video is in connection to the article "The case of a missing mobile phone (". It will help one to understand clearly the steps to track a lost android phone.
    Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

    760 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    8 Experts available now in Live!

    Get 1:1 Help Now