使用' out'在Linq查询中
我正在使用list
组件
对象,componentList
。
组件
具有方法getPosition
通过component.getPosition(out of position,out of arientation)返回组件的位置
。 我可以通过position.x,position.y,position.z
获得x,y,z。
我有一个单独的list< csvpart>
从CSV文件中导入的。每个列表项目也都有X,Y,Z。我想从CSV零件列表中找到匹配X,Y,Z的组件。
我尝试过:
foreach (CSVPart p in csvParts)
{
foundComponent = componentList
.Where(c => c.Name == p.PartNumber & ... == p.X & ... == p.Y & ... == p.Z
)
}
名称与partnumber相对应的地方,...对应于我茫然地盯着屏幕。 我已经尝试将后续语句嵌套以比较{}中的x,y,z,但是我尝试过任何尝试。如何将out
结果输入此LINQ查询?事先感谢您的帮助。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我建议您不要尝试以单个表达方式进行。相反,要么编写一个方法,该方法可以在查询中使用您想要的匹配并参考该方法,要么使用块状lambda :(
我已经从
中更改为
firstordOddordEfault
顾名思义,您正在尝试找到一个值...)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...)