TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
C# Corner
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Varios Ways to Remove Items from List
Kailash Chandra Behera
Jun 23
2015
Code
2.3
k
0
0
facebook
twitter
linkedIn
Reddit
WhatsApp
Email
Bookmark
expand
//Creating object of list
List<
string
> stringlist =
new
List<
string
>();
//adding items to list
stringlist.Add(
"a"
);
stringlist.Add(
"b"
);
stringlist.Add(
"c"
);
stringlist.Add(
"d"
);
stringlist.Add(
"e"
);
//deleting item by remove function by passing object
string
a= stringlist.FirstOrDefault(st => st ==
"a"
);
stringlist.Remove(a);
//deleting item by creating object internally by filtering
stringlist.Remove(stringlist.FirstOrDefault(st => st ==
"a"
));
//Remove items from list by passing filters
stringlist.RemoveAll(st => st ==
"a"
);
//Remove items by passing item index
stringlist.RemoveAt(0);
//remove range of element from list by passing start index and number of elements to delete
stringlist.RemoveRange(0, 2);
LINQ
Remove Items from List