The List<T> collection is the same as an ArrayList
except that List<T> is a generic collection whereas ArrayList is a
non-generic collection.so we can say that C# List<T> class is used to
store and fetch elements. It can have duplicate elements
Example of List<t> in c#:
|
using System;
using
System.Collections.Generic;
using System.Linq;
using System.Text;
using
System.Threading.Tasks;
namespace
ConsoleApplication1
{
class ListExampleProgram
{
static void Main(string[] args)
{
List<int> empSalaries = new List<int>();
empSalaries.Add(1000);
empSalaries.Add(2000);
empSalaries.Add(30000);
for (int i = 0; i <
empSalaries.Count; i++)
{
Console.WriteLine("Salary : {0}",
empSalaries[i]);
}
Console.ReadLine();
}
}
}
|