{"record":{"id":"fbd782156d37716b","repo":"TheAlgorithms/C-Sharp","slug":"both-points-should-have-the-same-dimensionality","errorCode":null,"errorMessage":"Both points should have the same dimensionality","messagePattern":"Both points should have the same dimensionality","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"Algorithms/LinearAlgebra/Distances/Chebyshev.cs","lineNumber":22,"sourceCode":"/// Implementation of Chebyshev distance.\n/// It is the maximum absolute difference between the measures in all dimensions of two points.\n/// In other words, it is the maximum distance one has to travel along any coordinate axis to get from one point to another.\n///\n/// It is commonly used in various fields such as chess, warehouse logistics, and more.\n/// </summary>\npublic static class Chebyshev\n{\n    /// <summary>\n    /// Calculate Chebyshev distance for two N-Dimensional points.\n    /// </summary>\n    /// <param name=\"point1\">First N-Dimensional point.</param>\n    /// <param name=\"point2\">Second N-Dimensional point.</param>\n    /// <returns>Calculated Chebyshev distance.</returns>\n    public static double Distance(double[] point1, double[] point2)\n    {\n        if (point1.Length != point2.Length)\n        {\n            throw new ArgumentException(\"Both points should have the same dimensionality\");\n        }\n\n        // distance = max(|x1-y1|, |x2-y2|, ..., |xn-yn|)\n        return point1.Zip(point2, (x1, x2) => Math.Abs(x1 - x2)).Max();\n    }\n}\n","sourceCodeStart":4,"sourceCodeEnd":29,"githubUrl":"https://github.com/TheAlgorithms/C-Sharp/blob/96e2905cab7bc6b33ac0a34ee5bb82ddccbcbb6c/Algorithms/LinearAlgebra/Distances/Chebyshev.cs#L4-L29","documentation":"Chebyshev.Distance computes max(|x_i - y_i|) over paired coordinates, which is only defined when both points have the same number of dimensions. When point1.Length != point2.Length it throws ArgumentException because the pairing (Zip) would silently drop extra coordinates otherwise.","triggerScenarios":"Calling Chebyshev.Distance(double[] point1, double[] point2) with arrays of different lengths, e.g., a 2D point compared with a 3D point, or a null/empty-dimensional mismatch from deserialized feature vectors.","commonSituations":"Machine-learning feature vectors assembled from different pipelines; merging datasets where one source added a feature column; accidental use of raw vs. normalized vectors of different widths.","solutions":["Verify point1.Length == point2.Length before calling Distance","Fix feature extraction so all vectors have the same dimensionality","Pad or truncate vectors to a common dimension as part of preprocessing","Catch ArgumentException at the comparison boundary and reject the mismatched pair"],"exampleFix":"// before\nChebyshev.Distance(new double[]{1,2}, new double[]{1,2,3}); // throws\n// after\nvar a = new double[]{1,2,0};\nvar b = new double[]{1,2,3};\nif (a.Length == b.Length) Chebyshev.Distance(a, b);","handlingStrategy":"validation","validationCode":"if (point1 == null || point2 == null || point1.Length != point2.Length) throw new ArgumentException(\"Points must be non-null and equally dimensional\");","typeGuard":"bool SameDimension(double[] a, double[] b) => a != null && b != null && a.Length == b.Length;","tryCatchPattern":"try { d = Chebyshev.Distance(a, b); }\ncatch (ArgumentException ex) { metrics.RecordInvalidVectorPair(ex); }","preventionTips":["Fix vector width at the feature-extraction boundary","Add a dimension assertion in vector-producing code","Keep schemas for vector inputs locked to a fixed length"],"tags":["csharp","linear-algebra","distance","dimensionality"],"backgroundTag":"shape-mismatch","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"}