public void AddBlock(VideoPacket NewBlock) { // need to insert at the correct time var Blocks = this.Blocks; System.Func <int, VideoPacket> GetAt = (Index) => { return(Blocks[Index]); }; System.Func <VideoPacket, BinaryChop.CompareDirection> Compare = (OtherBlock) => { //return OtherBlock.GetLineIndexDirection(NewBlock.StartLine); return(OtherBlock.GetTimeDirection(NewBlock.GetStartTime())); }; int?Match; int?NearestPrev; if (Blocks.Count == 0) { Match = null; NearestPrev = -1; } else { BinaryChop.Search(0, Blocks.Count - 1, GetAt, Compare, out NearestPrev, out Match); if (Match.HasValue) { throw new System.Exception("Block already exists in stream"); } } Blocks.Insert(NearestPrev.Value + 1, NewBlock); }