{"record":{"id":"1717ef661fd92b66","repo":"TheAlgorithms/C-Sharp","slug":"nameof-stepsize-should-be-greater-than-zero","errorCode":null,"errorMessage":"{nameof(stepSize)} should be greater than zero","messagePattern":"(.+?) should be greater than zero","errorType":"validation","errorClass":"ArgumentOutOfRangeException","httpStatus":null,"severity":"error","filePath":"Algorithms/Numeric/EulerMethod.cs","lineNumber":42,"sourceCode":"    /// <param name=\"yDerivative\">The right hand side of the differential equation.</param>\n    /// <returns>The solution of the Cauchy problem.</returns>\n    public static List<double[]> EulerFull(\n        double xStart,\n        double xEnd,\n        double stepSize,\n        double yStart,\n        Func<double, double, double> yDerivative)\n    {\n        if (xStart >= xEnd)\n        {\n            throw new ArgumentOutOfRangeException(\n                nameof(xEnd),\n                $\"{nameof(xEnd)} should be greater than {nameof(xStart)}\");\n        }\n\n        if (stepSize <= 0)\n        {\n            throw new ArgumentOutOfRangeException(\n                nameof(stepSize),\n                $\"{nameof(stepSize)} should be greater than zero\");\n        }\n\n        List<double[]> points = [];\n        double[] firstPoint = [xStart, yStart];\n        points.Add(firstPoint);\n        var yCurrent = yStart;\n        var xCurrent = xStart;\n\n        while (xCurrent < xEnd)\n        {\n            yCurrent = EulerStep(xCurrent, stepSize, yCurrent, yDerivative);\n            xCurrent += stepSize;\n            double[] point = [xCurrent, yCurrent];\n            points.Add(point);\n        }\n","sourceCodeStart":24,"sourceCodeEnd":60,"githubUrl":"https://github.com/TheAlgorithms/C-Sharp/blob/96e2905cab7bc6b33ac0a34ee5bb82ddccbcbb6c/Algorithms/Numeric/EulerMethod.cs#L24-L60","documentation":"Factorial.Calculate(inputNum) computes n! using BigInteger arithmetic and only defines the factorial for non-negative integers. A negative input throws ArgumentException with the terse message 'Only for num >= 0'. The comparison is done via BigInteger.Compare against BigInteger.Zero after converting the int input.","triggerScenarios":"Calling Calculate with a negative int, e.g. Factorial.Calculate(-1); passing a value that became negative through subtraction, user input, or a recursive formula base case handled incorrectly.","commonSituations":"Combinatorics formulas where intermediate terms can go negative (e.g. permutations with invalid arguments); unvalidated user input for n; gamma-function-style expectations that factorial extends to negatives (it does not here).","solutions":["Check inputNum >= 0 before calling and handle negatives in your own logic (return 0, throw your own clearer error, etc.).","If you need the gamma function for negative/non-integer arguments, use a math library that provides Gamma, not this factorial method.","Validate user input at the boundary so negative values never reach the calculation."],"exampleFix":"// before\nvar f = Factorial.Calculate(n); // throws when n < 0\n// after\nvar f = n >= 0 ? Factorial.Calculate(n) : BigInteger.Zero;","handlingStrategy":"validation","validationCode":"if (n < 0)\n    return BigInteger.Zero; // or throw a domain-specific error\nvar f = Factorial.Calculate(n);","typeGuard":null,"tryCatchPattern":"try\n{\n    f = Factorial.Calculate(n);\n}\ncatch (ArgumentException ex) when (ex.Message == \"Only for num >= 0\")\n{\n    f = BigInteger.Zero;\n}","preventionTips":["Check n >= 0 before any factorial call, especially inside combinatorics formulas.","Validate user input at the boundary.","Use a Gamma-function implementation for negative or non-integer arguments."],"tags":["argument-validation","math","factorial","csharp"],"backgroundTag":"invalid-argument-value","analyzedSha":"96e2905cab7bc6b33ac0a34ee5bb82ddccbcbb6c","analyzedAt":"2026-09-13T17:04:01.438Z","contentChangedAt":"2026-09-13T17:04:01.438Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}