List<T> class represents the list of objects which can be accessed by index. It comes under the System.Collection.Generic namespace. List class can be used to create a collection of different types like integers, strings etc. List<T> class also provides the methods to search, sort, and manipulate lists.
Example: List<T>
Example: List<T>
List<int> intList = new List<int>();
//Or
IList<int> intList = new List<int>();
Represents a strongly typed list of objects that can be accessed by index. Provides methods to search, sort, and manipulate lists.How to Add Elements into Lists[System.Serializable]public class List<T> : System.Collections.Generic.ICollection<T>, System.Collections.Generic.IEnumerable<T>, System.Collections.Generic.IList<T>, System.Collections.Generic.IReadOnlyCollection<T>, System.Collections.Generic.IReadOnlyList<T>, System.Collections.IList
using System;
using System.Collections.Generic;
public class Program
{
public static void Main()
{
IList<int> intList = new List<int>();
intList.Add(10);
intList.Add(20);
intList.Add(30);
intList.Add(40);
Console.WriteLine(intList.Count);
IList<string> strList = new List<string>();
strList.Add("one");
strList.Add("two");
strList.Add("three");
strList.Add("four");
strList.Add("four");
strList.Add(null);
strList.Add(null);
Console.WriteLine(strList.Count);
IList<Student> studentList = new List<Student>();
studentList.Add(new Student());
studentList.Add(new Student());
studentList.Add(new Student());
Console.WriteLine(studentList.Count);
}
}
public class Student
{
}
Tags:
Interview