- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- 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 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
- Related Articles
- How do you remove multiple items from a list in Python?
- C++ Program to remove items from a given vector
- How do I copy items from list to list without foreach in C#?
- How to dynamically remove items from ListView on a click?
- How to add items to a list in C#?
- Remove duplicates from a List in C#
- How to remove an element from Array List in C#?
- C# program to remove duplicate elements from a List
- Python Program to remove items from set
- Java program to remove items from Set
- How to remove index list from another list in python?
- How to remove an object from a list in Python?
- How to remove NULL values from a list in R?
- How to remove an element from a list in Python?
- How to remove an element from a Java List?

Advertisements