This feel really simple but I tried many scripts and nothing works.
I have an interface with Id field – named ITrust,
And I have a dictionary – Dictionary<string, Ilist<ITrust>>.
Now I’m trying to remove a single object from the list inside the dictionary but can’t find the right script.
I tried some things like that:
dictionaryName[keyName].Remove(x => x.Id == Id);
But it raise an exception –
Cannot convert lambda expression to type
ITrustbecause it is not a delegate type
Any one know the right script or maybe if there is a problem with might I try to do?
>Solution :
First off, that’s a compilation error, not an exception. And second, stop using IList<> if you don’t understand what it means.
If you use a normal List<>, you have a List.RemoveAll function that does exactly what you want.