
List is a collection of data. It is generic data type. List like strongly typed. We use generic data from the list. We can’t need to initialize the size of list. It is dynamically creating the size or index by the data. We can set the capacity of the list by the set the value of the list. We can call this list is Collections. Now given bellow the example code of the generic type list.
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using testForClass1;
namespace testFor
{
class Program
{
static void Main(string[] args)
{
List<Int32> myList = new List<int>();
myList.Add(10);
//myList.Add(5.5);
//myList.Add("jesy");
myList.Add(30);
myList.Add(5);
foreach (int data in myList)
{
Console.WriteLine("The value are : "+data+" Type of: "+data.GetType());
}
Console.WriteLine(myList.Capacity);
Console.WriteLine();
List<double> myListCapacity = new List<double>(5);
Console.WriteLine(myListCapacity.Capacity);
Console.Read();
}
}
}
In this section I was show the list. First create a list name as myList. This list type is integer. We can specify the list type so it is strongly type. In this section we can specify the capacity of the list by pass the parameter.