LinkedList

In this chapter you will learn:

  1. How to add elements to LinkedList

Adding to LinkedList

The following demonstrates the methods from LinkedList<T>: AddFirst, AddLast, AddBefore.

using System;//from j  a v  a2s .c  om
using System.Collections;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Text;


public class MainClass
{
    public static void Main()
    {
        LinkedList<int> list = new LinkedList<int>();

        list.AddFirst(10);             
        list.AddLast(15);              
        list.AddLast(3);               
        list.AddLast(99);              
        list.AddBefore(list.Last, 25); 

        LinkedListNode<int> node = list.First;
        while (node != null)
        {
            Console.WriteLine(node.Value);
            node = node.Next;
        }
    }
}

The code above generates the following result.

Next chapter...

What you will learn in the next chapter:

  1. How to use ForEach to process each element in a List
  2. ForEach with anonymous delegate