C
C#•4w ago
mwc

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
lycian
lycian•4w ago
Without knowing exact $detail I'm guessing it would be to add '&& p.Value == "JP1"' in the all
mwc
mwcOP•4w ago
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
lycian
lycian•4w ago
Can you share the $code?
MODiX
MODiX•4w ago
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/
mwc
mwcOP•4w ago
OK, I'm an idiot. For some reason during my various attempts, I'd swapped the Where to Any
lycian
lycian•4w ago
Haha it happens
mwc
mwcOP•4w ago
Thanks for the help!
lycian
lycian•4w ago
$closed Damn I thought that was it. Oh well 😅
Mayor McCheese
Mayor McCheese•4w ago
@mtreit .ToList()
Want results from more Discord servers?
Add your server