{"record":{"id":"bbae8ac0d8db061e","repo":"TheAlgorithms/C-Sharp","slug":"lower-bound-must-be-greater-than-0","errorCode":null,"errorMessage":"Lower bound must be greater than 0.","messagePattern":"Lower bound must be greater than 0\\.","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"Algorithms/Numeric/AutomorphicNumber.cs","lineNumber":23,"sourceCode":"/// if the square of the number will contain the number itself at the end.\n/// </summary>\npublic static class AutomorphicNumber\n{\n    /// <summary>\n    /// Generates a list of automorphic numbers that are between <paramref name=\"lowerBound\"/> and <paramref name=\"upperBound\"/>\n    /// inclusive.\n    /// </summary>\n    /// <param name=\"lowerBound\">The lower bound of the list.</param>\n    /// <param name=\"upperBound\">The upper bound of the list.</param>\n    /// <returns>A list that contains all of the automorphic numbers between <paramref name=\"lowerBound\"/> and <paramref name=\"upperBound\"/> inclusive.</returns>\n    /// <exception cref=\"ArgumentException\">If the <paramref name=\"lowerBound\"/>\n    /// or <paramref name=\"upperBound\"/> is not greater than zero\n    /// or <paramref name=\"upperBound\"/>is lower than the <paramref name=\"lowerBound\"/>.</exception>\n    public static IEnumerable<int> GetAutomorphicNumbers(int lowerBound, int upperBound)\n    {\n        if (lowerBound < 1)\n        {\n            throw new ArgumentException($\"Lower bound must be greater than 0.\");\n        }\n\n        if (upperBound < 1)\n        {\n            throw new ArgumentException($\"Upper bound must be greater than 0.\");\n        }\n\n        if (lowerBound > upperBound)\n        {\n            throw new ArgumentException($\"The lower bound must be less than or equal to the upper bound.\");\n        }\n\n        return Enumerable.Range(lowerBound, upperBound).Where(IsAutomorphic);\n    }\n\n    /// <summary>\n    /// Checks if a given natural number is automorphic or not.\n    /// </summary>","sourceCodeStart":5,"sourceCodeEnd":41,"githubUrl":"https://github.com/TheAlgorithms/C-Sharp/blob/96e2905cab7bc6b33ac0a34ee5bb82ddccbcbb6c/Algorithms/Numeric/AutomorphicNumber.cs#L5-L41","documentation":"GetAutomorphicNumbers throws ArgumentException when lowerBound < 1, because automorphic numbers start at 1 and the generator expects a positive range start. Documented via the XML exception note that bounds must be greater than zero.","triggerScenarios":"Calling GetAutomorphicNumbers(lowerBound, upperBound) with lowerBound of 0 or negative, e.g. GetAutomorphicNumbers(0, 100).","commonSituations":"Using 0 as a natural 'start from beginning' value; ranges derived from user input or config defaults of 0; loop variables starting at zero passed straight through.","solutions":["Pass lowerBound >= 1 (use 1 to scan from the start of the sequence).","Clamp: lowerBound = Math.Max(1, lowerBound) before the call.","Validate range inputs at the UI/config boundary."],"exampleFix":"// before\nvar nums = AutomorphicNumber.GetAutomorphicNumbers(0, 100);\n// after\nvar nums = AutomorphicNumber.GetAutomorphicNumbers(Math.Max(1, lower), 100);","handlingStrategy":"validation","validationCode":"if (lowerBound < 1) throw new ArgumentOutOfRangeException(nameof(lowerBound), \"must be >= 1\");","typeGuard":"static bool IsValidRangeStart(int lower) => lower >= 1;","tryCatchPattern":"try { seq = AutomorphicNumber.GetAutomorphicNumbers(lo, hi); }\ncatch (ArgumentException ex) when (ex.Message.Contains(\"Lower bound\")) { /* clamp lo to 1 and retry */ }","preventionTips":["Map 'start from the beginning' to 1, not 0.","Clamp lower bounds with Math.Max(1, lo).","Validate UI/config ranges before invoking generators."],"tags":["csharp","math","range-validation"],"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"}