Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Remove single item from a list inside a dictionary

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 –

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

Cannot convert lambda expression to type ITrust because 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.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading