How to insert an item into List at specific index in C#

1 Answer

0 votes
using System;
using System.Collections.Generic;

namespace ConsoleApplication_C_Sharp
{
    class Program
    {
        static void Main(string[] args)
        {
            List<string> list = new List<string>();

            list.Add("c#");
            list.Add("java");
            list.Add("c");
            list.Add("c++");
            list.Add("python");

            list.Insert(2, "php");

            foreach (string s in list)
                Console.WriteLine(s);
        }
    }
}


/*
run:
      
c#
java
php
c
c++
python

*/

 



answered Dec 27, 2016 by avibootz

Related questions

1 answer 74 views
1 answer 127 views
1 answer 181 views
3 answers 192 views
...