我试图重构为一个查询这样的:重构嵌套循环到一个单一的LINQ查询
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?
无论如何,你stil会遍历每个项目,所以这个重构的目的是什么? –
什么是'''什么是'replacedCode'?你能提供一个简单的例子和期望的结果吗? –