Tutorial :How to remove stuff from a list in C#?



Question:

I have a list of structs:

list<structure>;  

But I want to remove the specific stuff by ID.

Example: item with ID 55.

So how I can reomve a stuff from list?

I have an ID in the struct as public string stuffID;

How can I do this?


Solution:1

To remove everything with an ID of 55:

List<Structure> list;  list.RemoveAll(structure => structure.ID == 55);  


Solution:2

list = list.Where(item => item.id != 55).ToList();


Note:If u also have question or solution just comment us below or mail us on toontricks1994@gmail.com
Previous
Next Post »