How to copy StringCollection to array start at specific index in C#

1 Answer

0 votes
using System;
using System.Collections.Specialized; 
					
public class Program
{
	public static void Main()
	{
		StringCollection sc = new StringCollection(); 
  
        sc.Add("c#"); 
        sc.Add("c++"); 
        sc.Add("java"); 
        sc.Add("php"); 
        sc.Add("python"); 

		String[] arr = new String[sc.Count + 1];
 		
		arr[0] = "javascript";
		
		sc.CopyTo(arr, 1); 
		
		foreach (string s in arr) {
            Console.WriteLine(s);
        }
	}
}



/*
run:

javascript
c#
c++
java
php
python

*/

 



answered May 9, 2020 by avibootz
edited May 9, 2020 by avibootz

Related questions

1 answer 169 views
1 answer 146 views
1 answer 135 views
1 answer 142 views
1 answer 177 views
1 answer 176 views
...