Created
February 27, 2013 06:40
-
-
Save narcotics726/5045718 to your computer and use it in GitHub Desktop.
Nested lmbda expression to find or remove repeated collection item within a few lines 利用嵌套lambda表达式快速查找或移除重复集合项
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
List<string> listA = new List<string>(){"1","2","3","4"}; | |
List<string> listB = new List<string>(){"1","3","5"}; | |
List<string> listAWithoutRepeatedItemsInListB = listA.RemoveAll(objA=>(listB.Exist(objB=>objB==objA))); | |
//result: "2","4" | |
List<string> listAllDiffItems = new List<string>(); | |
listAllDiffItems.AddRange(ListA.FindAll(objA=>(!listB.Exist(objB=>objB==objA)))); | |
listAllDiffItems.AddRange(ListB.FindAll(objB=>(!listA.Exist(objA=>objA==objB)))); | |
//result: "2","4","5" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment