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
How to pop the first element from a C# List?
To pop the first element in the list, use the RemoveAt() method. It eliminates the element from the position you want to remove the element.
Set the list
List<string> myList = new List<string>() {
"Operating System",
"Computer Networks",
"Compiler Design"
};
Now pop the first element using RemoveAt(0)
myList.RemoveAt(0);
Let us see the complete example.
Example
using System;
using System.Collections.Generic;
using System.Linq;
class Program {
static void Main() {
List<string> myList = new List<string>() {
"Operating System",
"Computer Networks",
"Compiler Design"
};
Console.Write("Initial list...");
foreach (string list in myList) {
Console.WriteLine(list);
}
Console.Write("Removing first element from the list...");
myList.RemoveAt(0);
foreach (string list in myList) {
Console.WriteLine(list);
}
}
}
Output
Initial list... Operating System Computer Networks Compiler Design Removing first element from the list... Computer Networks Compiler Design
Advertisements