0
다음 루프가 있습니다. 이 루프는 책 모음을 탐색하고 체크인 및 체크 아웃 날짜와 관련하여 몇 가지 논리 검사를 수행합니다. 그런 다음 새 객체를 반환합니다. 또한 책 제목을 뒤섞습니다.중첩 루프의 카운터 추적
컬렉션이 끝날 때까지 제대로 작동합니다. 그런 다음 카운터가 동기화되지 않은 것처럼 보이며 끝없는 반복이됩니다. 다른 permitation을 시도했지만, 나는 제대로 작동하지 않습니다.
눈에 띄지 않는 사람이 볼 수 있습니까?
감사합니다.
private static readonly TimeSpan gracePeriodTimeSpan = TimeSpan.Parse("23:00");
//current posistion in books collection
currentPos = pos % books.Count;
//posistion to stop at
var stopPos = books.Count;
do
{
//start is current posistion
var startPos = pos;
//assign the next posistion
var nextPos = (pos + 1) % books.Count;
bookTitle = bookTitle + ";" + books[pos].Title;
//loop until we hit the stop posistion - check book CheckInDate/CheckOutDate proximity
while ((nextPos != stopPos || nextPos !=0) && books[pos].CheckInDate + gracePeriodTimeSpan >= books[nextPos].CheckOutDate)
{
pos = nextPos;
nextPos = (pos + 1) % books.Count;
}
bookTitle = bookTitle + ";" + books[pos].Title;
//return new book checkout object
yield return
CreateNewBookCheckout(bookTitle, books[pos], books[startPos].CheckOutDate,
books[pos].CheckInDate);
bookTitle = "";
pos = nextPos;
//keep going til we hit the stop posistion
} while (pos != stopPos);
감사하는 마지막 책으로 당신의
stopPos
을 전환 할 필요가있다. 이렇게하면 끝날 때까지 카운터가 고정됩니다. 루핑이 콜렉션의 마지막 책을 건너 뜁니다. – SkyeBoniwell