How to copy collection to array in C#

1 Answer

0 votes
using System;
using System.Collections.ObjectModel; 

class Program
{
    static void Main() {
        Collection<string> col = new Collection<string>(); 
 
        col.Add("c#"); 
        col.Add("c++"); 
        col.Add("c"); 
        col.Add("java"); 
 
        string[] arr = new string[col.Count]; 
  
        col.CopyTo(arr, 0); 

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

*/

 



answered Apr 21, 2020 by avibootz

Related questions

2 answers 247 views
1 answer 83 views
83 views asked Mar 26, 2024 by avibootz
1 answer 101 views
1 answer 116 views
1 answer 191 views
2 answers 256 views
...