Introduction to List in C#

In this article I will explain the overview of list in C#
  • 3274

Introduction

A list is a collection of items that can be accessed by index and provides functionality to search, sort and manipulate list items. The List<T> class is the generic equivalent of the ArrayList class. But List<> type in the C# resizes dynamically and arrays do not dynamically resize. We need to use < and > in the List declaration. The namespace that we use for the list is System.Collection.Generic. We can create a list<> using the following syntax.

Syntax

List<datatype> NameOfList= new List<datatype>();

Example

The following code snippet creates a List of string types.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace addlist
{
     class Program
        {
              static void Main(string[] args)
             {

               List<int> list1 = new List<int>();
             }
        }
}

Ask Your Question 

Got a programming related question? You may want to post your question here

Programming Answers here

© 2020 DotNetHeaven. All rights reserved.