gpt4 book ai didi

c# - 将嵌套循环重构为单个 LINQ 查询

转载 作者:太空宇宙 更新时间:2023-11-03 18:11:49 26 4
gpt4 key购买 nike

我正在尝试将其重构为一个查询:

 while (IsRunning)
{

...

//specialPoint is a string
foreach (PointTypeItem pointTypeItem in PointTypeItemCollection)
{
foreach (PointItem pointItem in pointTypeItem.PointItemCollection)
{
//Replace the point name with point ID
if (specialPoint.Contains(pointItem.PointName))
{
replacedCode += s.Replace(specialPoint , pointItem.ID);
//I want to go back to the beginning point of while (IsRunning) from here
//Simply putting continue; here won't work
}
}
}
}

我基本上想把它变成一个 LINQ 查询,但我坚持要写一个。实际上,我什至不确定我的方向是否正确。

var results = from pointTypeItem in ddcItem.PointTypeItemCollection
where pointTypeItem.PointItemCollection.Any(pointItem => pointName.Contains(pointItem.PointName))
select //What do I select?

最佳答案

var results = from pointTypeItem in ddcItem.PointTypeItemCollection
from pointItem in pointTypeItem.PointItemCollection
where specialPoint.Contains(pointItem.PointName)
select pointItem.ID;

获取 IEnumerable<<i>the type of pointItem.ID</i>> .

关于c# - 将嵌套循环重构为单个 LINQ 查询,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13474133/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com