Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

List(T) RemoveAll() not working as intended...?

Let's say I have a list of User objects with two properties...ID and Name

List<User> lst = List<User>();

I fill it up with a bunch of Users. Ok, now I want to trim my list using RemoveAll() and this function.

private Boolean IsExisting(int id) {
//blah blah
return true;
//blah blah
return false;
}

So I use this statement:

gdvFoo.DataSource = lst.RemoveAll(t => IsExisting(t.ID));

It is my understanding that whenever IsExisting returns true that element should be removed from lst, but what happens, strangely enough, is it returns an integer?, not a truncated list and I received the following error message:

Data source is an invalid type. It must be either an IListSource, IEnumerable, or IDataSource.>

like image 413
bulltorious Avatar asked Oct 25 '25 06:10

bulltorious


1 Answers

List.RemoveAll method

The method removes all matching instances from the list on which you called it. This modifies the existing list, rather than returning a new one.

The return value is the number of rows removed.

like image 183
Bryan Watts Avatar answered Oct 27 '25 18:10

Bryan Watts



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!