Skip to content

Instantly share code, notes, and snippets.

@narcotics726
Created February 27, 2013 06:40
Show Gist options
  • Save narcotics726/5045718 to your computer and use it in GitHub Desktop.
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表达式快速查找或移除重复集合项
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