I'm clearly missing something here... I have a generic list of objects and I'm trying to use a lambda expression to remove items. When I use the code posted below I get the following exception.
System.InvalidOperationException: Sequence contains no matching element
public class MyObject {
public Guid ID1 {get;set;}
public int ID2 {get;set;}
}
public class MyContainer{
List<MyObject> myList = new List<MyObject>();
public MyObject Get(Guid id1) {
return myList.Single(mo => mo.ID1 == id1);
}
public void AddItem(MyObject item) {
myList.Add(item);
}
public int RemoveItems(MyObject item) {
return myList.RemoveAll(mo => mo.ID1 == item.ID1 || mo.ID2 == item.ID2);
}
}
Am I making a mistake using a lambda?
[EDIT] Well a flop for the first question. I misread the stack trace, after removing the item in my unit test I tried to call the Get() method and in my "why is it already dark out" rage jumped the gun on posting a question without appropriate analysis. Sorry.