LinkedList RemoveFirst() Method in C#


Let’s say the following is our LinkedList with integer nodes.

int [] num = {29, 40, 67, 89, 198, 234};
LinkedList<int> myList = new LinkedList<int>(num);

Now, if you want to remove the first element from the list, then use the RemoveFirst() method.

myList.RemoveFirst();

Example

 Live Demo

using System;
using System.Collections.Generic;
class Demo {
   static void Main() {
      int [] num = {29, 40, 67, 89, 198, 234};
      LinkedList<int> myList = new LinkedList<int>(num);
      foreach (var n in myList) {
         Console.WriteLine(n);
      }
      // removing first node
      myList.RemoveFirst();
      Console.WriteLine("LinkedList after removing the first node...");
      foreach (var n in myList) {
         Console.WriteLine(n);
      }
   }
}

Output

29
40
67
89
198
234
LinkedList after removing the first node...
40
67
89
198
234

karthikeya Boyini
karthikeya Boyini

I love programming (: That's all I know

Updated on: 23-Jun-2020

377 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements