1
我的LINQ到XML的foreach循環是提前和意外終止。沒有例外。這是怎麼回事?Linq到XML爲循環終止早期和意外
var doc = XDocument.Parse("<a><b>one</b><b>two</b></a>");
foreach(var element in doc.Root.Elements("b"))
{
element.ReplaceWith(XElement.Parse("<c>fixed</c>"));
}
doc.Dump();
給我
<a>
<c>fixed</c>
<b>two</b>
</a>
當我預計
<a>
<c>fixed</c>
<c>fixed</c>
</a>