How to insert element at the specific index in StringCollection with 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"); 

		foreach (string s in sc) {
            Console.WriteLine(s);
        }
 		
		sc.Insert(3, "nodejs"); 
		
		Console.WriteLine(); 
		
		foreach (string s in sc) {
            Console.WriteLine(s);
        }
        
	}
}



/*
run:

c#
c++
java
php
python

c#
c++
java
nodejs
php
python

*/

 



answered May 9, 2020 by avibootz

Related questions

1 answer 122 views
1 answer 144 views
1 answer 144 views
1 answer 100 views
1 answer 187 views
...