Kennyist
Kennyist

Reputation: 63

c# Removing an object from list based on 2 variables

I'm trying to remove an object from a list, First I need to get all the entries in it with the id == 0(for now) and then remove the first entry. At the moment I'm trying:

coursework.Where( x => x.Id == moduleList.SelectedIndex).remove(coursework[testList.SelectedIndex]) // Doesnt exist in this context

But that doesn't work and I've tried many things but can never find anything that works.

Upvotes: 0

Views: 591

Answers (1)

SLaks
SLaks

Reputation: 887275

.Where() returns an IEnumerable<T> containing matched items.
It cannot be used to modify the original list.

Instead, you should call .RemoveAll().

Upvotes: 1

Related Questions