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
LinkedList RemoveLast() Method in C#
Firstly, declare a LinkedList and add nodes.
int [] num = {92, 98, 110, 130, 145, 170, 230, 240, 250, 300, 330};
LinkedList<int> myList = new LinkedList<int>(num);
Remove the last node from the LinkedList using the RemoveLast() method.
myList.RemoveLast();
Example
using System;
using System.Collections.Generic;
class Demo {
static void Main() {
int [] num = {92, 98, 110, 130, 145, 170, 230, 240, 250, 300, 330};
LinkedList<int> myList = new LinkedList<int>(num);
foreach (var n in myList) {
Console.WriteLine(n);
}
// removing last node
myList.RemoveLast();
Console.WriteLine("LinkedList after removing the last node...");
foreach (var n in myList) {
Console.WriteLine(n);
}
}
}
Output
92 98 110 130 145 170 230 240 250 300 330 LinkedList after removing the last node... 92 98 110 130 145 170 230 240 250 300
Advertisements