public SABlock GetNextBlock(SABlock block, bool forward) { SA parentSA = block.ParentSA; int indexBlock = parentSA.Blocks.IndexOf(block); if (indexBlock != -1) { int nextIndex = indexBlock + (forward ? 1 : -1); if (0 <= nextIndex && nextIndex < parentSA.Blocks.Count) { return(parentSA.Blocks[nextIndex]); } } if (forward) { return(parentSA.GetFirstBlock()); } else { return(parentSA.GetLastBlock()); } }