Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8357443
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T10:28:35+00:00 2026-06-09T10:28:35+00:00

I have the following code: //In a Class: private BlockingCollection<T>[] _collectionOfQueues; // In the

  • 0

I have the following code:

//In a Class:
private BlockingCollection<T>[] _collectionOfQueues;
// In the Constructor:
_collectionOfQueues = new BlockingCollection<T>(new ConcurrentQueue<T>())[4];

I get the following error for the bottom line:

Cannot apply indexing with [] to an expression of type ‘System.Collection.Concurrent.BlockingCollection’

Even if I do:

_collectionOfQueues = new BlockingCollection<T>(new ConcurrentQueue<T>())[];

I get an error on the last square brace:

Syntax error; value expected

I am trying to make an array of BlockingCollection with the collection of ConcurrentQueue so that I can do:

_collectionOfQueues[1].Add(...);
// Add an item to the second queue

What am I doing wrong and what can I do to fix it? Can I not create an array of BlockingCollection and do I have to make a list of it?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T10:28:37+00:00Added an answer on June 9, 2026 at 10:28 am

    You want to create a four element array of BlockingCollection<T> instances and you want to initialize each instance with a constructor that accepts a ConcurrentQueue<T> instance. (Note that the default constructor for BlockingCollection<T> will use a ConcurrentQueue<T> as the backing collection so you could get away by using the default constructor instead, but for demonstration purpose I’ll stick with the construction from the question.)

    You can either do this using a collection initializer:

    BlockingCollection<T>[] _collectionOfQueues = new[] {
      new BlockingCollection<T>(new ConcurrentQueue<T>()),
      new BlockingCollection<T>(new ConcurrentQueue<T>()),
      new BlockingCollection<T>(new ConcurrentQueue<T>()),
      new BlockingCollection<T>(new ConcurrentQueue<T>())
    };
    

    Or you can do it using some kind of loop. Using LINQ is probably the easiest way to do it:

    BlockingCollection<T>[] _collectionOfQueues = Enumerable.Range(0, 4)
      .Select(_ => new BlockingCollection<T>(new ConcurrentQueue<T>()))
      .ToArray();
    

    Note that you in some way need to provide the code to initialize each element in the array. It seems that your problem is that you expect C# to have some functionality to create arrays with elements all initialized using the same constructor that you only specify once, but that is not possible.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following code: public class Search { private Desktop desktop = new
I have the following code: class Orders{ /** * * @var Supplier */ private
I have the following code: class Foo<T> where T : struct { private T
I have the following code: public class Test extends JFrame implements ActionListener{ private static
I have the following code: Imports MySql.Data.MySqlClient Imports MySql.Data.Types Public Class FormMain Private Sub
I have the following code: public partial class queryTerm : System.Web.UI.UserControl { private static
I have following code class User attr_accessor :name end u = User.new u.name =
I have the following code: Public Class Form1 Private Function Step1_Execute() As Boolean Return
I have the following code : public class Main { private int i =
I have an issue with the following code : class quicksort { private: void

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.