{"record":{"id":"58ebea883d67cdcf","repo":"TheAlgorithms/C-Sharp","slug":"upper-bound-must-be-greater-than-0","errorCode":null,"errorMessage":"Upper bound must be greater than 0.","messagePattern":"Upper bound must be greater than 0\\.","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"Algorithms/Numeric/AutomorphicNumber.cs","lineNumber":28,"sourceCode":"    /// 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>\n    /// <param name=\"number\">The number to check.</param>\n    /// <returns>True if the number is automorphic, false otherwise.</returns>\n    /// <exception cref=\"ArgumentException\">If the number is non-positive.</exception>\n    public static bool IsAutomorphic(int number)\n    {","sourceCodeStart":10,"sourceCodeEnd":46,"githubUrl":"https://github.com/TheAlgorithms/C-Sharp/blob/96e2905cab7bc6b33ac0a34ee5bb82ddccbcbb6c/Algorithms/Numeric/AutomorphicNumber.cs#L10-L46","documentation":"GetAutomorphicNumbers throws ArgumentException when upperBound < 1, since the range must end at a positive number. This is the second bound check, after the lowerBound check and before the lowerBound <= upperBound check.","triggerScenarios":"Calling GetAutomorphicNumbers(lowerBound, upperBound) with upperBound of 0 or negative, e.g. GetAutomorphicNumbers(1, 0).","commonSituations":"Empty range requests encoded as (1, 0) instead of an early return; upper limits computed from data that can be zero/negative; config defaults of 0 for 'no limit'.","solutions":["Pass upperBound >= 1; if you need 'no limit', pick a large positive constant instead of 0.","Clamp: upperBound = Math.Max(1, upperBound) or skip the call entirely when the requested range is empty.","Validate bounds together: require 1 <= lowerBound <= upperBound before calling."],"exampleFix":"// before\nvar nums = AutomorphicNumber.GetAutomorphicNumbers(1, upper); // upper may be 0\n// after\nvar nums = upper >= 1 ? AutomorphicNumber.GetAutomorphicNumbers(1, upper) : Enumerable.Empty<int>();","handlingStrategy":"validation","validationCode":"if (upperBound < 1) return Enumerable.Empty<int>(); // empty requested range, skip call\nif (lowerBound < 1 || lowerBound > upperBound) throw new ArgumentOutOfRangeException(nameof(lowerBound));","typeGuard":"static bool IsValidRange(int lo, int hi) => lo >= 1 && hi >= 1 && lo <= hi;","tryCatchPattern":"try { seq = AutomorphicNumber.GetAutomorphicNumbers(lo, hi); }\ncatch (ArgumentException ex) when (ex.Message.Contains(\"Upper bound\")) { /* treat as empty range or fix hi */ }","preventionTips":["Encode empty ranges as early returns, not (1, 0).","Use large positive constants for 'unbounded' rather than 0.","Validate both bounds together before calling."],"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"}