{"record":{"id":"97aab1ac53fa14f2","repo":"TheAlgorithms/C-Sharp","slug":"position-is-out-of-size","errorCode":null,"errorMessage":"Position is out of size","messagePattern":"Position is out of size","errorType":"validation","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"DataStructures/UnrolledList/UnrolledLinkedListNode.cs","lineNumber":24,"sourceCode":"public class UnrolledLinkedListNode(int nodeSize)\n{\n    private readonly int[] array = new int[nodeSize];\n\n    public UnrolledLinkedListNode Next { get; set; } = null!;\n\n    public int Count { get; set; }\n\n    /// <summary>\n    /// Set new item in array buffer.\n    /// </summary>\n    /// <param name=\"pos\">Index in array.</param>\n    /// <param name=\"val\">The entered value.</param>\n    /// <exception cref=\"ArgumentException\">Index is out of scope.</exception>\n    public void Set(int pos, int val)\n    {\n        if (pos < 0 || pos > array.Length - 1)\n        {\n            throw new ArgumentException(\"Position is out of size\", nameof(pos));\n        }\n\n        array[pos] = val;\n        Count++;\n    }\n\n    /// <summary>\n    /// Get item from array buffer.\n    /// </summary>\n    /// <param name=\"pos\">Index in array.</param>\n    /// <exception cref=\"ArgumentException\">Index is out of scope.</exception>\n    public int Get(int pos)\n    {\n        if (pos < 0 || pos > array.Length - 1)\n        {\n            throw new ArgumentException(\"Position is out of size\", nameof(pos));\n        }\n","sourceCodeStart":6,"sourceCodeEnd":42,"githubUrl":"https://github.com/TheAlgorithms/C-Sharp/blob/96e2905cab7bc6b33ac0a34ee5bb82ddccbcbb6c/DataStructures/UnrolledList/UnrolledLinkedListNode.cs#L6-L42","documentation":"UnrolledLinkedListNode.Set throws ArgumentException when the requested position is negative or beyond the node's internal array capacity (pos > array.Length - 1). The node's backing array has fixed capacity, so only indices 0..Length-1 are valid write positions.","triggerScenarios":"Calling Set(pos, val) with pos < 0 or pos >= the node's array length — e.g. Set(5, x) on a node whose array length is 5, or Set(-1, x).","commonSituations":"Off-by-one when writing at the last slot (using array.Length instead of Length-1); passing a global list index instead of the node-local offset; inserting into an unrolled linked list with an incorrectly computed node-local position.","solutions":["Validate 0 <= pos < node's array capacity before calling Set","Convert a global list position to the correct node-local offset before writing","Catch ArgumentException at a higher level if the position source is untrusted"],"exampleFix":"// before\nnode.Set(index, value); // index is a list-level position\n// after\nif (index < 0 || index >= node.ArrayLength)\n{\n    throw new ArgumentOutOfRangeException(nameof(index));\n}\nnode.Set(index, value);","handlingStrategy":"validation","validationCode":"if (pos < 0 || pos >= node.ArrayLength)\n    throw new ArgumentOutOfRangeException(nameof(pos), \"Position outside node capacity.\");\nnode.Set(pos, val);","typeGuard":null,"tryCatchPattern":"try { node.Set(pos, val); }\ncatch (ArgumentException ex) { /* map to user-facing 'index out of range' message */ }","preventionTips":["Use `<` (not `<=`) with Length when iterating node slots","Convert global list positions to node-local offsets in one well-tested helper","Clamp or validate any user-supplied index before writing"],"tags":["c-sharp","data-structures","unrolled-linked-list","argument-out-of-range"],"backgroundTag":"argument-out-of-range","analyzedSha":"96e2905cab7bc6b33ac0a34ee5bb82ddccbcbb6c","analyzedAt":"2026-09-13T17:04:01.438Z","contentChangedAt":"2026-09-13T17:04:01.438Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}