ちょっと人々 昨日、私はいくつかのコードで作業していましたが、foreachの繰り返しを保存し、リスト<>働く後で私は、lamdaを使ってforeachを使うようにコードをリファクタリングしました。ここでstatementと私の項目evrytimeが見つかりました。作業バージョン技術的な理由:この繰り返しは私のアイテムを見つけられないのです
private XmlCell FindCell(string id)
{
XmlSection section = new XmlSection(SectionNode);
XmlCell currentCell = null;
foreach (XmlBlock block in section.Blocks)
{
foreach (XmlRow row in block.Rows)
{
currentCell = row.Cells.Find(cell => string.Equals(cell.Id, id));
}
}
Assert.IsNotNull(currentCell, string.Format("Cell with id {0} not found", id));
return currentCell;
}
::バージョンを動作していない
:コードの
私の2つのバージョンが下に掲載されている
XmlSection section = new XmlSection(SectionNode);
XmlCell currentCell = null;
foreach (XmlBlock block in section.Blocks)
{
foreach (XmlRow row in block.Rows)
{
foreach (XmlCell cell in row.Cells.Where(cell => string.Equals(cell.Id, id)))
{
return cell;
}
}
}
Assert.IsNotNull(currentCell, string.Format("Cell with id {0} not found", id));
return currentCell;
コードの最初のビットが取得いけない理由誰かがPLX説明できますジョブが完了したら、findメソッドはリスト内で最初に見つかったインスタンスを返します。
「コレクションが変更されたため、列挙操作が実行できない可能性があります」というエラーが発生しました。なぜですか?