{"record":{"id":"f0ea1c0d826a2809","repo":"louthy/language-ext","slug":"indexoutofrangeexception-seqstrict","errorCode":null,"errorMessage":"IndexOutOfRangeException","messagePattern":"IndexOutOfRangeException","errorType":"exception","errorClass":"IndexOutOfRangeException","httpStatus":null,"severity":"error","filePath":"LanguageExt.Core/Immutable Collections/Seq/DSL/SeqStrict.cs","lineNumber":94,"sourceCode":"    /// Add constructor (called in the Add function only)\n    /// </summary>\n    [MethodImpl(MethodImplOptions.AggressiveInlining)]\n    public SeqStrict(A[] data, int start, int count)\n    {\n        this.data = data;\n        this.start = start;\n        this.count = count;\n        consDisallowed = NoCons;\n    }\n\n    /// <summary>\n    /// Indexer\n    /// </summary>\n    public A this[int index]\n    {\n        [MethodImpl(MethodImplOptions.AggressiveInlining)]\n        get => index < 0 || index >= count\n                   ? throw new IndexOutOfRangeException()\n                   : data[start + index];\n    }\n\n    /// <summary>\n    /// Indexer\n    /// </summary>\n    [MethodImpl(MethodImplOptions.AggressiveInlining)]\n    public Option<A> At(int index) =>\n        index < 0 || index >= count\n            ? default(Option<A>)\n            : data[start + index];\n\n    /// <summary>\n    /// Add an item to the end of the sequence\n    /// </summary>\n    /// <remarks>\n    /// Forces evaluation of the entire lazy sequence so the item \n    /// can be appended","sourceCodeStart":76,"sourceCodeEnd":112,"githubUrl":"https://github.com/louthy/language-ext/blob/2f0e3628242889774d4141960a35671a0280051f/LanguageExt.Core/Immutable Collections/Seq/DSL/SeqStrict.cs#L76-L112","documentation":"This IndexOutOfRangeException is a range guard in the SeqStrict<A> indexer: it throws when the index is negative or >= count of the materialized array slice. The faulting input is the index argument; it fires on out-of-range access rather than wrapping, so callers must validate the index against Count first.","triggerScenarios":"seq[i] with i < 0 or i >= seq.Count on a strict (array-backed) seq; slicing with start offsets then indexing with absolute rather than slice-relative indices.","commonSituations":"Off-by-one loops (i <= Count); using indices computed against the original collection after Skip/Take produced a slice; iterating a filtered seq with original indices.","solutions":["Validate 0 <= index && index < seq.Count before indexing","Use slice-relative indices when indexing the result of Skip/Take","Use At/HeadOrNone Option-based access when length is uncertain","Convert to array and use standard bounds-checked loops for heavy random access"],"exampleFix":"// before\nfor (var i = 0; i <= seq.Count; i++) Use(seq[i]);\n// after\nfor (var i = 0; i < seq.Count; i++) Use(seq[i]);","handlingStrategy":"type-guard","validationCode":"bool inBounds = index >= 0 && index < seq.Count;","typeGuard":"Option<A> TryAt<A>(SeqStrict<A> seq, int i) => i >= 0 && i < seq.Count ? seq[i] : Option<A>.None;","tryCatchPattern":"try { x = seq[index]; }\ncatch (IndexOutOfRangeException)\n{ x = fallback; }","preventionTips":["Use strict i < Count bounds in loops","Use slice-relative indices after Skip/Take","Prefer At()/pattern matching over the throwing indexer for uncertain bounds"],"tags":["csharp","languageext","seq","index-out-of-range"],"backgroundTag":"index-out-of-range","analyzedSha":"2f0e3628242889774d4141960a35671a0280051f","analyzedAt":"2026-09-15T03:31:55.716Z","contentChangedAt":"2026-09-15T03:31:55.716Z","schemaVersion":2},"datasetVersion":"2026-09-16T09:17:16.951Z"}