{"record":{"id":"8a960d23bd3e07ce","repo":"krahets/hello-algo","slug":"error-8a960d","errorCode":null,"errorMessage":"インデックスが範囲外です","messagePattern":"インデックスが範囲外です","errorType":"exception","errorClass":"IndexOutOfRangeException","httpStatus":null,"severity":"error","filePath":"ja/codes/csharp/chapter_array_and_linkedlist/my_list.cs","lineNumber":35,"sourceCode":"    public MyList() {\n        arr = new int[arrCapacity];\n    }\n\n    /* リストの長さを取得（現在の要素数） */\n    public int Size() {\n        return arrSize;\n    }\n\n    /* リスト容量を取得する */\n    public int Capacity() {\n        return arrCapacity;\n    }\n\n    /* 要素にアクセス */\n    public int Get(int index) {\n        // インデックスが範囲外なら例外を送出する。以下同様\n        if (index < 0 || index >= arrSize)\n            throw new IndexOutOfRangeException(\"インデックスが範囲外です\");\n        return arr[index];\n    }\n\n    /* 要素を更新 */\n    public void Set(int index, int num) {\n        if (index < 0 || index >= arrSize)\n            throw new IndexOutOfRangeException(\"インデックスが範囲外です\");\n        arr[index] = num;\n    }\n\n    /* 末尾に要素を追加 */\n    public void Add(int num) {\n        // 要素数が容量を超えると、拡張機構が発動する\n        if (arrSize == arrCapacity)\n            ExtendCapacity();\n        arr[arrSize] = num;\n        // 要素数を更新\n        arrSize++;","sourceCodeStart":17,"sourceCodeEnd":53,"githubUrl":"https://github.com/krahets/hello-algo/blob/69932aed1891a7b7f6a0de88cd116d3fe13e7032/ja/codes/csharp/chapter_array_and_linkedlist/my_list.cs#L17-L53","documentation":"IndexOutOfRangeException with message \"インデックスが範囲外です\" (Japanese for \"index is out of range\") is thrown by MyList.Get(int index) when index < 0 or index >= arrSize. This is the Japanese-localized equivalent of the English my_list.cs; the logic is identical.","triggerScenarios":"Calling Get(index) where index < 0 or index >= list.Size(). On a newly constructed MyList (arrSize 0), any Get call throws.","commonSituations":"Off-by-one loop bounds, unvalidated external index input, or reading from a list before populating it. Japanese-speaking developers may search for the localized message string.","solutions":["Validate 0 <= index < list.Size() before calling Get().","Fix loop bounds to use < Size() rather than <= Size().","Clamp or reject out-of-range indices from external input."],"exampleFix":"// before\nMyList list = new();\nlist.Add(10);\nint val = list.Get(1); // throws\n\n// after\nif (index >= 0 && index < list.Size())\n    int val = list.Get(index);","handlingStrategy":"validation","validationCode":"if (index >= 0 && index < list.Size()) {\n    int val = list.Get(index);\n}","typeGuard":null,"tryCatchPattern":"try {\n    int val = list.Get(index);\n} catch (IndexOutOfRangeException ex) when (ex.Message.Contains(\"範囲外\")) {\n    // index out of bounds — handle\n}","preventionTips":["Use i < list.Size() in loops, never i <= list.Size().","Validate externally-sourced indices before calling Get().","When catching by message, match the localized string \"インデックスが範囲外です\"."],"tags":["csharp","array","index-out-of-bounds","precondition","list","japanese","i18n"],"backgroundTag":null,"analyzedSha":"69932aed1891a7b7f6a0de88cd116d3fe13e7032","analyzedAt":"2026-08-13T23:02:37.581Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}