Console C#.Net Tutorial

Visual Studio.NET IDE

Define C#.NET

C# Comment

C# Variables

C# Data Types

C# Escape Sequence

C# Operators

Format String

Operator Precedence

C# Keywords

Constant Variable

Type Conversion

Flow Control

C# Arrays

C# Character

C# Strings

User-Define Methods

Variable Scope

C# Enumerations

C# Structure

C# Exception Handling

Object Oriented Programming

C# Classes

Constructor & Destructor

C# Inheritance

C# Polymorphism

C# Operator Overloading

C# Method Overriding

C# Interface

Abstract Classes & Methods

Sealed Classes, Methods

C# Properties

C# Indexer

C# Delegates

C# Generics

C# Collection

C# ArrayList

C# Stack

C# Queue

C# HashTable

C# SortedList

Page Stats

Visitor: 212

C#.Net Collection

The size of arrays is fixed, if the number of elements is dynamic, you should use collection classes that hold many values or objects. Collection represents a set of objects that you can access by stepping through each element. The .NET framework provides specialized classes for managing collection and these classes have rich capability for enhancing your programming experience through better performance and easy maintenance. Object class is the base class of every type in .NET. All the collections implement IEnumerable interface that is extended by ICollection interface. IDictionary and IList are also interfaces for collection which are derived from ICollection.

Various Classes in Collection namespace are:

  • ArrayList Class
  • Stack Class
  • Queue Class
  • Linked List Class
  • Dictionary
    • Hashtable Class
    • SortedList Class

Linked List Class

A linked list is a linear collection of self-referential class objects called nodes, connected by reference links. Data is stored in a linked list dynamically, each node is created as necessary.

Advantage of Linked List is:

Linked lists provide better memory utilization because they can grow and shrink at execution time thus, saves memory.

LinkedList <int> alist = new LinkedList <int>();
alist.AddFirst(10);
alist.AddAfter(alist.Last ,20);
alist.AddAfter(alist.Last, 30);
alist.AddAfter(alist.Last, 40);
foreach (int i in alist )
{
	Console.WriteLine(i);
}
Updated: 10-Sep-21