How to insert element at specific index in a list with C#

1 Answer

0 votes
using System;
using System.Collections.Generic;
					
public class Program
{
	public static void Main()
	{
		var lst = new List<string>() { "c#", "php", "nodejs", "java", "c" };

        lst.Insert(2, "c++");
         
		foreach (string s in lst) {
            Console.WriteLine(s);
        }
	}
}



/*
run:

c#
php
c++
nodejs
java
c

*/

 



answered May 6, 2020 by avibootz

Related questions

1 answer 88 views
1 answer 156 views
1 answer 231 views
1 answer 113 views
1 answer 102 views
1 answer 144 views
...