我試圖重構爲一個查詢這樣的:重構嵌套循環到一個單一的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'?你能提供一個簡單的例子和期望的結果嗎? –