【发布时间】:2012-11-20 13:21:08
【问题描述】:
我正在尝试将其重构为查询:
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?
【问题讨论】:
-
反正你还是会遍历每一项,那么这次重构的目的是什么?
-
s是什么,replacedCode是什么?你能提供一个简单的例子和期望的结果吗?