0

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.

1 Answer 1

1

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

Instead, you should call .RemoveAll().

Sign up to request clarification or add additional context in comments.

2 Comments

How would I do that so it only removes the one with matching ID and then the matching [] ID?
@Kennyist: RemoveAll takes a lambda expression specifying which items to remove (just like Where()).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.