How to copy queue to array starting at the specified index in C#

1 Answer

0 votes
using System;
using System.Collections;
 
class Program
{
    static void Main() {
        Queue queue = new Queue(); 
 
        queue.Enqueue("c#"); 
        queue.Enqueue("c++"); 
        queue.Enqueue("c"); 
        queue.Enqueue("java"); 
 
        String[] arr = new String[10]; 

        arr[0] = "aaa"; 
        arr[1] = "bbb"; 
        
        queue.CopyTo(arr, 2); 

        foreach(Object obj in arr) { 
            Console.WriteLine(obj); 
        } 
    }
}
 
 
 
/*
run:
 
aaa
bbb
c#
c++
c
java

*/

 



answered Apr 21, 2020 by avibootz

Related questions

...