
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 Items from a List in C#
Firstly, set a list and add elements.
List<string> myList = new List<string>(); myList.Add("Jennings"); myList.Add("James"); myList.Add("Chris");
Let’s say you need to delete the element “James” now. For that, use the Remove() method.
myList.Remove("James");
Here is the complete code.
Example
using System.Collections.Generic; using System; class Program { static void Main() { List<string> myList = new List<string>(); myList.Add("Jennings"); myList.Add("James"); myList.Add("Chris"); Console.WriteLine("Initial List..."); foreach(string str in myList) { Console.WriteLine(str); } myList.Remove("James"); Console.WriteLine("New List..."); foreach(string str in myList) { Console.WriteLine(str); } } }
Output
Initial List... Jennings James Chris New List... Jennings Chris
Advertisements