How to remove list items from list1 which mats condition with list2 items using LINQ without duplicates
I know how to do it in simple foreach way but i want the same using Linq style single line code.
How to do it using Linq?
Input list
list1 = new List(){new object{id = 40},new object{id = 50},new object{id = 60}}
list2 = new List(){new object{id = 400},new object{id = 50},new object{id = 600}}
Run Code Online (Sandbox Code Playgroud)
Expected Output should from
list1
new object{id = 40},new object{id = 60}
You can remove the elements like this:
list1.RemoveAll(item => list2.Any(item2 => item.Key == item2.Key))
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
3768 次 |
| 最近记录: |