score:5
Accepted answer
removeall modifies your existing list, it returns the number of items it removed. to get a new list without the items you can use
var newlist = mylist.where(i => !excludeditems.any(ei => ei.id == i.id)).tolist();
although if your server
class has the right equality members to compare ids, you could just write
var newlist = mylist.except(servers).tolist();
score:1
try this
list<target> allservers = gettargets(group.id);
list<long> excludedservers = getexcludedservers();
list<target> patchservers = allservers
.where(x => !excludedservers.any(y => y.id == x.id)).tolist();
score:1
you could do something like this
patchservers = allservers.where(x => !excludedservers.contains(x.id)).tolist();
Source: stackoverflow.com
Related Query
- Removing items from a list where the Id is in another list
- Select items from a List where the children contain the items from another List using LINQ
- Using LINQ to get a list of items where the item contains a part of an item from another list
- Removing a single item from an enumerable source when the items are equal
- linq how to select the parent from a collection where the parent contains child items in another collection
- Select items from List A where the property is not in List B
- How do I retrieve items from a List<T> where one property contains exactly the words from another list?
- Is there a Linq operation to retrieve specific items from a list of items where the item has a property value for a property which should be unique?
- removing items from list that exist in another list based on an ID member
- Get the items from a list that match all itens from another list
- Filtering or removing array objects from the DTO class object based on an another list in .net
- Linq - NHibernate - get all classes where the dictionary property contains one of the items from my list
- Retrieve all the items from a table where the text of a table column is contained in a list of items (ASP.NET Core 2.2 C# LINQ)
- How to construct a LINQ Query to test a list against another list where elements start with the elements from the other
- LINQ: Select where object does not contain items from list
- Remove items of list from another lists with criteria
- Find items from a list which exist in another list
- Get specific property from all items from the list
- How do I move items from a list to another list in C#?
- Exclude list items that contain values from another list
- Linq - How to select items from a list that contains only items of another list?
- in C#, how do I order items in a list where the "largest" values are in the middle of the list
- Removing a list of objects from another list
- Generating the Shortest Regex Dynamically from a source List of Strings
- LINQ select List where sub-list contains item from another list
- Select Rows from a DataSet using LINQ, where the list of RowsID's are in a List<T>
- Check if one list contains all items from another list in order
- Why does adding a list to another list, using add range, remove the elements from the first list?
- Using Linq, get all items from list that are in another List<int>
- linq remove items from query where any list value is present
More Query from same tag
- How to map two expressions of differing types?
- Handling large SQL queries with LINQ
- How would a write a LINQ query to compare with a list of values?
- Is there a way to analyse how a particular Linq-to-objects query will execute?
- C#, check whether integer array has negative numbers in it
- Changing LINQ-to-SQL connection string at runtime
- LINQ Join to find items NOT IN a list
- How to catch an exception only if another exception as not occured in C#
- Linq expression could not be translated Error Entity Framework Core 3
- Linq XML select last parent and insert element
- JSON on LINQ, dynamic query method
- Get values from database with specific time interval
- Left Join on Linq to Entity issue
- Not able to understand LINQ extension methods
- How can I efficiently link two datasets in C#?
- How can I take the information I received with linq and use that information in an if else statement?
- Sort List by date values
- In Entity Framework EntityState.Detached makes operation slow
- How to count the occurence of each number in list A that is exist in list B and return zero if not existed?
- How to get First character of FirstName Property from List<T>
- Is there a neater linq way to 'Union' a single item?
- Dictionary<K, List<TObject>> from collection of objects
- Use method for child property in entity framework query
- asp.net mvc 4.0 linq query with datetime field returns something like this /Date(1391600738810)/
- Get result from list inside list
- Linq query to traverse tables
- Linq perform join with updated field
- Should my query return null when it doesn't find any items?
- How to iterate in a list to find names and values with linq
- NDepend Linq mixing the output of one query with another