Link to home
Start Free TrialLog in
Avatar of sonbinary
sonbinary

asked on

Problem Queue..!!!!!!

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...!!!
Avatar of Babycorn-Starfish
Babycorn-Starfish
Flag of United States of America image

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
Avatar of Razzie_
Razzie_

Quick way to do this might be:

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

HTH.

Razzie
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.
Avatar of sonbinary

ASKER

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

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

What kind of collection are you using? The 'Queue' class does not have a method 'ToCharArray()'.
           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.
ASKER CERTIFIED SOLUTION
Avatar of Mudie
Mudie

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
sorry ToArray() is method of the Queue ..I'm sorry..