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

x
?
Solved

Problem Queue..!!!!!!

Posted on 2005-04-29
8
Medium Priority
?
240 Views
Last Modified: 2010-04-16
I have a queue with some items in it.....now I wan't to get these items to an array like this  :
string[] a=myQueue.ToCharArray();

but it return an error....help me...!!!
0
Comment
Question by:sonbinary
  • 3
  • 2
  • 2
  • +1
8 Comments
 
LVL 11

Expert Comment

by:Babycorn-Starfish
ID: 13894407
Hi,

what type are the items in the Queue? I don't think Queue has a ToCharArray() method, but there'll be a way round it.

BCS
0
 
LVL 8

Expert Comment

by:Razzie_
ID: 13894499
Quick way to do this might be:

Object[] testArray = myQueue.ToArray();
foreach(string s in testArray)
   Debug.WriteLine(s);

HTH.

Razzie
0
 
LVL 8

Expert Comment

by:Razzie_
ID: 13894506
Of course, this is when the items in the queue are of type string. If you have an other type in it, just cast them to the right type.
0
Industry Leaders: 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!

 

Author Comment

by:sonbinary
ID: 13902610
the items in the queue is string ...so coding here, it have a problem....:

string[] a=(string[])myQueue.ToCharArray();

0
 
LVL 8

Expert Comment

by:Razzie_
ID: 13903610
What kind of collection are you using? The 'Queue' class does not have a method 'ToCharArray()'.
0
 
LVL 2

Expert Comment

by:Mudie
ID: 13905727
           private void button1_Click(object sender, System.EventArgs e)
            {
                  Queue myQueue = new Queue();

                  myQueue.Enqueue("a");
                  myQueue.Enqueue("b");
                  myQueue.Enqueue("c");
            
                  Object[] myArray = myQueue.ToArray();

                  MessageBox.Show(Convert.ToString(myArray[0]));/*Displays a*/
            }

There is no ToCharArray for Queue. I hope the above code does what you want.
0
 
LVL 2

Accepted Solution

by:
Mudie earned 2000 total points
ID: 13905760
private void button1_Click(object sender, System.EventArgs e)
            {
                  Queue myQueue = new Queue();

                  myQueue.Enqueue("a");
                  myQueue.Enqueue("b");
                  myQueue.Enqueue("c");

                  System.Collections.IEnumerator myQueueEnumerator = myQueue.GetEnumerator();
                  string[] myStringArray = new string[ myQueue.Count ];

                  int i = 0;
                  while (myQueueEnumerator.MoveNext())
                  {
                        myStringArray[ i ] = Convert.ToString(myQueueEnumerator.Current);
                        MessageBox.Show(myStringArray [ i ]);
                        i += 1;

                  }

            }

The above code will put it in a string array rather then an object array, I'm not seeing an easy way to do this.
0
 

Author Comment

by:sonbinary
ID: 13906684
sorry ToArray() is method of the Queue ..I'm sorry..
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Summary: Persistence is the capability of an application to store the state of objects and recover it when necessary. This article compares the two common types of serialization in aspects of data access, readability, and runtime cost. A ready-to…
We all know that functional code is the leg that any good program stands on when it comes right down to it, however, if your program lacks a good user interface your product may not have the appeal needed to keep your customers happy. This issue can…
Look below the covers at a subform control , and the form that is inside it. Explore properties and see how easy it is to aggregate, get statistics, and synchronize results for your data. A Microsoft Access subform is used to show relevant calcul…
With just a little bit of  SQL and VBA, many doors open to cool things like synchronize a list box to display data relevant to other information on a form.  If you have never written code or looked at an SQL statement before, no problem! ...  give i…
Suggested Courses

830 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