Blog

Use List in C#

Jun 29, 2013 Blogs | .NET 4.5
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.

Sourav Kayal

I am .NET learner passionate logger, like to .NET eat and sleep.  Have little experience in Web technology with new development platform including node.js, MVC Web API. Feel free to teach me .NET...

  • 23rank
  • 1M readers
  • 2times
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