
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Remove Node at the End of a Linked List in C#
The following is our LinkedList.
string [] employees = {"Patrick","Robert","John","Jacob", "Jamie"}; LinkedList<string> list = new LinkedList<string>(employees);
Now, let’s say you need to remove the last node i.e. “Jamie”. For that, use the RemoveLast() method.
list.RemoveLast();
Example
using System; using System.Collections.Generic; class Demo { static void Main() { string [] employees = {"Patrick","Robert","John","Jacob", "Jamie"}; LinkedList<string> list = new LinkedList<string>(employees); foreach (var emp in list) { Console.WriteLine(emp); } // removing last node list.RemoveLast(); Console.WriteLine("LinkedList after removing last node..."); foreach (var emp in list) { Console.WriteLine(emp); } } }
Output
Patrick Robert John Jacob Jamie LinkedList after removing last node... Patrick Robert John Jacob
Advertisements