Remove instances from a list by using LINQ or Lambda?

前端 未结 7 1579
囚心锁ツ
囚心锁ツ 2021-02-05 03:26

Now I come a stage to get all my data as a list in cache(objects) and my next thing I have to do is to remove some instances from the list.

Normally, I would do removing

7条回答
  •  梦谈多话
    2021-02-05 03:54

    You can use LINQ's Where method to filter out values that should not be a part of the list. The result is an IEnumerable with the elements removed.

    var res = list.Where(item => !(one.Value1 == item.Value1 && one.Value2 < item.Value2));
    

    This will not updated the original List instance but instead will create a new IEnumerable with the values removed.

提交回复
热议问题