Click here to Skip to main content
15,880,796 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,
I created a queue in c# windows application. Now I want to copy this queue to integer array. How can I do this?

What I have tried:

C#
Queue q = new Queue();
if (result == TPCANStatus.PCAN_ERROR_OK)
{
    result = PCANBasic.Read(PCANBasic.PCAN_USBBUS2, out msg);
    q.Enqueue(msg.DATA);
}
Posted
Updated 6-Apr-16 20:13pm
v2
Comments
VR Karthikeyan 7-Apr-16 1:38am    
just use .ToArray() method.
Member 10994712 7-Apr-16 2:46am    
I tried that.. but here msg is a structure

Try the Queue.ToArray Method (System.Collections)[^]
C#
object[] are = q.ToArray();

Or better, use the generic Queue<T> version, and get strong typing.
 
Share this answer
 
Use .ToArray() method, it Copies the Queue elements to a new array.
see below snippet

C#
Queue<int> numbers = new Queue<int>();
        numbers.Enqueue(1);
        numbers.Enqueue(2);
        numbers.Enqueue(3);
        numbers.Enqueue(4);

        int[] arrInt = numbers.ToArray();
        foreach( int number in arr)
        {
            Console.WriteLine(number);
        }</int></int>


I have take int queue in int array, if you have string Queue, that needs to be convert in int array, you might use convert.toInt32 method to convert it to int
Hope it helps
 
Share this answer
 
Comments
Member 10994712 8-Apr-16 2:44am    
I tried this. Here data is a byte array.
and also I tried to convert data to byte array but I got following error
"Unable to cast object of type 'System.Byte[]' to type 'System.IConvertible'."
koolprasad2003 9-Apr-16 0:57am    
Where is byte in my code ? Please post your code so that I can help you better

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900