{"record":{"id":"cd0c152145979d45","repo":"TheAlgorithms/C-Sharp","slug":"nameof-xend-should-be-greater-than-nameof-xstart-cd0c15","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/RungeKuttaMethod.cs","lineNumber":30,"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=\"function\">The right hand side of the differential equation.</param>\n    /// <returns>The solution of the Cauchy problem.</returns>\n    public static List<double[]> ClassicRungeKuttaMethod(\n        double xStart,\n        double xEnd,\n        double stepSize,\n        double yStart,\n        Func<double, double, double> function)\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\n        var yCurrent = yStart;\n        var xCurrent = xStart;\n","sourceCodeStart":12,"sourceCodeEnd":48,"githubUrl":"https://github.com/TheAlgorithms/C-Sharp/blob/96e2905cab7bc6b33ac0a34ee5bb82ddccbcbb6c/Algorithms/Numeric/RungeKuttaMethod.cs#L12-L48","documentation":"ClassicRungeKuttaMethod integrates an ODE from xStart to xEnd using RK4; the interval must have positive length, so it throws ArgumentOutOfRangeException for xEnd when xStart >= xEnd, naming xEnd as the offending parameter. An equal end/start is also rejected since no integration steps would occur.","triggerScenarios":"Calling ClassicRungeKuttaMethod with xEnd == xStart or xEnd < xStart, e.g. integrating backwards in time.","commonSituations":"Computing xEnd from a duration that ended up 0 or negative (bad config), or attempting backward integration which this API does not support.","solutions":["Ensure xEnd > xStart; if integrating backward, negate the step and swap endpoints or use a solver that supports negative direction.","Validate the interval at the caller before invoking.","Check where xEnd is computed from config/duration; fix the source value."],"exampleFix":"// before\nsolver.ClassicRungeKuttaMethod(t0, t0, y0, f); // tEnd == tStart\n// after\nvar tEnd = t0 + duration; // duration > 0 validated\nvar result = solver.ClassicRungeKuttaMethod(t0, tEnd, y0, f);","handlingStrategy":"validation","validationCode":"if (xEnd <= xStart) throw new ArgumentOutOfRangeException(nameof(xEnd), \"xEnd must be greater than xStart\");\nvar points = ClassicRungeKuttaMethod(xStart, xEnd, stepSize, yStart, f);","typeGuard":null,"tryCatchPattern":"try { var pts = ClassicRungeKuttaMethod(x0, x1, h, y0, f); }\ncatch (ArgumentOutOfRangeException ex) when (ex.ParamName == \"xEnd\") { /* fix interval or use a backward-capable integrator */ }","preventionTips":["Validate interval endpoints where duration/config is read","Remember this API integrates forward only; swap endpoints manually for backward problems","Unit-test the degenerate interval xEnd == xStart"],"tags":["argument-out-of-range","ode-solver","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"}