Blog

Use List in C#

By Sourav Kayal Blogs | .NET 4.5 Jun 29, 2013
Here i am going to show how to 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.

COMMENT USING

PREMIUM SPONSORS

Hire Mobile & Web Developer on demand. 100% satisfaction. Try for 1 week or Money Back. Local and remote developers available all over USA.

Latest Blogs