{"record":{"id":"52b6967fcbc55243","repo":"TheAlgorithms/C-Sharp","slug":"nameof-xend-should-be-greater-than-nameof-xstart","errorCode":null,"errorMessage":"{nameof(xEnd)} should be greater than {nameof(xStart)}","messagePattern":"(.+?) should be greater than (.+?)","errorType":"validation","errorClass":"ArgumentOutOfRangeException","httpStatus":null,"severity":"error","filePath":"Algorithms/Numeric/EulerMethod.cs","lineNumber":35,"sourceCode":"    ///     Loops through all the steps until xEnd is reached, adds a point for each step and then\n    ///     returns all the points.\n    /// </summary>\n    /// <param name=\"xStart\">Initial conditions x-value.</param>\n    /// <param name=\"xEnd\">Last x-value.</param>\n    /// <param name=\"stepSize\">Step-size on the x-axis.</param>\n    /// <param name=\"yStart\">Initial conditions y-value.</param>\n    /// <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)","sourceCodeStart":17,"sourceCodeEnd":53,"githubUrl":"https://github.com/TheAlgorithms/C-Sharp/blob/96e2905cab7bc6b33ac0a34ee5bb82ddccbcbb6c/Algorithms/Numeric/EulerMethod.cs#L17-L53","documentation":"EulerMethod.EulerFull throws ArgumentOutOfRangeException when stepSize <= 0. The explicit Euler method advances the solution by fixed positive steps; a zero or negative step size would cause an infinite loop or backward integration the method does not support.","triggerScenarios":"Calling EulerFull with stepSize = 0 or a negative value; a step size computed as (xEnd - xStart) / steps where steps was 0 or the interval was inverted, yielding zero/negative results.","commonSituations":"Step count computed from an empty or reversed time range; configuration where stepSize defaults to 0 before being set; sign error when converting a 'dt' parameter from another library that allows negative steps.","solutions":["Pass a strictly positive stepSize: validate stepSize > 0 before calling.","If deriving stepSize from (xEnd - xStart) / steps, guard steps >= 1 and xEnd > xStart first.","Clamp or reject non-positive configured step sizes at config-load time with a clear message."],"exampleFix":"// before\nvar h = (xEnd - xStart) / steps; // steps == 0 => h = 0 => throws\nvar points = EulerMethod.EulerFull(xStart, xEnd, h, y0, f);\n// after\nif (steps < 1) throw new ArgumentException(\"steps must be >= 1\");\nvar h = (xEnd - xStart) / steps;\nvar points = EulerMethod.EulerFull(xStart, xEnd, h, y0, f);","handlingStrategy":"validation","validationCode":"if (stepSize <= 0)\n    throw new ArgumentException(\"stepSize must be positive\");\nvar points = EulerMethod.EulerFull(xStart, xEnd, stepSize, yStart, yDerivative);","typeGuard":null,"tryCatchPattern":"try\n{\n    var points = EulerMethod.EulerFull(xStart, xEnd, h, y0, f);\n}\ncatch (ArgumentOutOfRangeException ex) when (ex.ParamName == \"stepSize\")\n{\n    // use a default positive step or surface config error\n}","preventionTips":["Guard division when deriving stepSize from an interval and step count.","Ensure configured step sizes are strictly positive at load time.","Remember this implementation only integrates forward with positive steps."],"tags":["argument-out-of-range","numerical-methods","ode","csharp"],"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-16T04:17:20.429Z"}