Use List in C#

List in C#

List class in one of Collection class of .NET Class library. You have to include using System.Collections.Generic; namespace in order to use collection class in your program.

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

namespace BlogProject

{

    class Program

    {

        static void Main(string[] args)

        {

            List<Int32> lst = new List<int>();

            lst.Add(100);

            lst.Add(200);

            lst.Remove(100);

            Console.WriteLine(lst[0]);

            Console.ReadLine();

        }

    }

}

Create object of List class like this

List<Int32> lst = new List<int>();

To insert data in list object use Add() function. Like below.

lst.Add(100);

To remove particular object from list we have to use Remove() function of List class object. Like

lst.Remove(100);

to get any index value use lst[index]. That is object-name[index]

I have given simple code in below.

Ebook Download
View all
Learn
View all