c# - Remove instances from a list by using LINQ or Lambda? -
Now I have come across a platform for getting all my data in the list of caches (objects) The next thing I have to do is to remove some examples from the list.
Generally, I would like to delete:
list & lt; T & gt; List; & Lt; T2 & gt; ToBeRemovedItems; // Divide foreach of two lists (broken items in T2 items) {make a condition based on {list.Remove (representative (t one) {// item // return right or wrong}};}
To be more specific, I actually create or populate a list of dynamic classes (not a formal defined class) in the Barmowowight list. For example, And to remove the code like:
class MyClass & Lt; C & gt; {Public String Value1 {get} Set;} Public Int Value 2 {Received; Set;} Public ObjectC {get; Set;}} .... List & lt; MyClass & lt; C An example of hard-coded code is var toBeRemovedLItems = new [] {new1 value1 = "a", Value2 = 1}, new {value2 = " X ", Value2 = 10}, ...}; // toBeRemovedItems Select from a collection foreach (var items in toBeRemovedLItems) {list.Remove (Rep (MyClass one) {return one.Value1 = item.Value1 & amp; Amp; a. Value 2 & lt; item.value2;}); }
I tried to search the extract () method from MSDN in the IEnumerable interface, but I can not find the method () to remove (it is understood that IEnumerable just calculates Is used for). In the list class, remove many overloaded (...) methods, I am not sure whether there is any alternative way of removing items in the list using LINQ or Lambda expressions?
By the way, I considered the way to do a query against a list to get a cabinet, a new IEnumerable list where the conditions are similar to moving items from a list. However, I prefer to remove items from my cached list, and in some cases I can not reset the list property in a property in a list (for example, the private set).
You can use the Remove method:
< Pre> MyClass one; // Start a MyClass list. Remove all (items => a.value1 == item value1 and a.value 2 -
Comments
Post a Comment