Tech
News
Videos
Forums
Jobs
Books
Events
More
Interviews
Live
Learn
Training
Career
Members
Blogs
Challenges
Certification
Contribute
Article
Blog
Video
Ebook
Interview Question
Collapse
Feed
Dashboard
Wallet
Learn
Achievements
Network
Rewards
SharpGPT
Premium
Contribute
Article
Blog
Video
Ebook
Interview Question
Register
Login
How to remove an Item from a C# List
WhatsApp
Mahesh Chand
6y
114.3k
0
1
100
Article
Remove Items
The Remove method removes the first occurrence of a specific object from a List. The Remove method takes an item as its parameter.
We can use the RemoveAt method to remove an item at the specified position within a List.
The following code snippet removes an item from a List.
// Create a list of strings
List<
string
> AuthorList =
new
List<
string
>();
AuthorList.Add(
"Mahesh Chand"
);
AuthorList.Add(
"Praveen Kumar"
);
AuthorList.Add(
"Raj Kumar"
);
AuthorList.Add(
"Nipun Tomar"
);
AuthorList.Add(
"Dinesh Beniwal"
);
AuthorList.Remove(
"Mahesh Chand"
);
The RemoveAt method removes an item at the specified zero based index. The following code snippet removes an item at 2nd position in the List.
AuthorList.RemoveAt(2);
The RemoveRange method removes a number of items based on the specified starting index and number of items. The RemoveRange method takes first parameter as the starting position and second parameter as the number of the items to be removed from the List. The following code snippet removes 2 items starting at the 3rd position.
AuthorList.RemoveRange(3, 2);
Next>>
Working with C# List
List.RemoveAt
remove item in List
RemoveAt method
Up Next
Ebook Download
View all
Printing in C# Made Easy
Read by 22.4k people
Download Now!
Learn
View all
Mindcracker
Founded in 2003, Mindcracker is the authority in custom software development and innovation. We put best practices into action. We deliver solutions based on consumer and industry analysis.
Membership not found