Search object Inner list for value
My googlefu is failing for this one.
I have a list of an outer class (Board) that contains a (inner) list of another class (Properties).
Properties is essentially a dictionary (the object gets saved to XML, and you can't serialise a dictionary) with two properties, Property and Value, which are used to store various properties of the parent/outer class.
What I'm need to do, is search the inner list for a defined property (Connector), with a specific value (JP1).
I have suitable Linq that returns all the Board's, which have a Property set with the Property of Connector, but I'm struggling with how to check if that Property is set to JP1-
boards = Boards.Where(x => x.Properties.All(p => p.Property == "Connector")).ToList();
Can anybody point me in the correct direction?
9 Replies
Without knowing exact $detail I'm guessing it would be to add '&& p.Value == "JP1"' in the all
I never tried that obvious solution, but having just tried it, it doesn't match
But adding a foreach loop to loop through and test each property, it does match
Can you share the $code?
To post C# code type the following:
```cs
// code here
```
Get an example by typing
$codegif
in chat
For longer snippets, use: https://paste.mod.gg/OK, I'm an idiot.
For some reason during my various attempts, I'd swapped the Where to Any
Haha it happens
Thanks for the help!
$closed
Damn I thought that was it. Oh well 😅
@mtreit
.ToList()