I am working with a List
of Component
objects, componentList
.
Component
has method GetPosition
which returns position of a component via component.GetPosition(out position, out orientation)
.
I can get X, Y, Z via position.X, position.Y, position.Z
.
I have a separate List<CSVPart>
imported from a CSV file. Each list item also has X, Y, Z. I want to find Component
which matches X, Y, Z from the list of CSV parts.
I have tried:
foreach (CSVPart p in csvParts)
{
foundComponent = componentList
.Where(c => c.Name == p.PartNumber & ... == p.X & ... == p.Y & ... == p.Z
)
}
Where Name corresponds to PartNumber and ... corresponds to me staring blankly at the screen.
I've tried nesting the subsequent statements to compare X, Y, Z in {} but nothing I've tried worked. How do I get the out
results into this Linq query? Thanks in advance for help.
I would suggest you don't try to do it in a single expression. Instead, either write a method that does the matching you want and refer to that in your query, or use a block-bodied lambda:
(I've changed from
Where
toFirstOrDefault
as the name suggests you're trying to find a single value...)