top button
Flag Notify
    Connect to us
      Site Registration

Site Registration

How to Add item to the beginning of List in C# ?

0 votes
347 views
How to Add item to the beginning of List in C# ?
posted Jul 27, 2016 by Sathyasree

Share this question
Facebook Share Button Twitter Share Button LinkedIn Share Button

1 Answer

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

namespace ACCode 
{ 
    class Program 
    { 
        static void Main(string[] args) 
        { 
            List<string> LstItems = new List<string>(); 
            LstItems.Add("One"); 
            LstItems.Add("Two"); 
            LstItems.Add("Three"); 
            LstItems.Add("Four");

            // Adds an item to the beginning of the list 
            LstItems.Insert(0,"Five");

            foreach (var item in LstItems) 
            { 
                Console.WriteLine(item); 
            } 
            Console.ReadLine(); 
        }       
    } 
}
answer Jul 27, 2016 by Shivaranjini
...