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 109 views
1 answer 187 views
1 answer 100 views
...