How to insert an element in C# list
Now we are going to learn about how to insert an element in C#.
Introduction
In this article we will learn about inserting of an element in list of C#. We know that it is not possible to increase the size of array length dynamically. But C# provides us a special facility that is the list in C#. There is a string to insert in index 4. But it is inserted in the location of index 5. In list of C# we can easily increase or decrease the length of list. Now there is an example of insert an elements in list in C#. There is a syntax of the list is ( < > ) sign used.
Example
class program
{
static void Main()
{
List<string> Man = new List<string>();
Man.Add("Raju");
Man.Add("satish");
Man.Add("sandeep");
Man.Add("narender");
Man.Add("Ravinder");
Man.Add("satender");
Man.Insert(4, "Manoj");
foreach (string value in Man)
{
Console.WriteLine(value);
Console.ReadLine();
}
}
}
}
Output