{"record":{"id":"530b243617cc1215","repo":"TheAlgorithms/C-Sharp","slug":"value-cannot-be-null-parameter-jobs","errorCode":null,"errorMessage":"Value cannot be null. (Parameter 'jobs')","messagePattern":"Value cannot be null\\. \\(Parameter 'jobs'\\)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"Algorithms/Problems/JobScheduling/IntervalSchedulingSolver.cs","lineNumber":22,"sourceCode":"\nnamespace Algorithms.Problems.JobScheduling;\n\n/// <summary>\n/// Implements the greedy algorithm for Interval Scheduling.\n/// Finds the maximum set of non-overlapping jobs.\n/// </summary>\npublic static class IntervalSchedulingSolver\n{\n    /// <summary>\n    /// Returns the maximal set of non-overlapping jobs.\n    /// </summary>\n    /// <param name=\"jobs\">List of jobs to schedule.</param>\n    /// <returns>List of selected jobs (maximal set).</returns>\n    public static List<Job> Schedule(IEnumerable<Job> jobs)\n    {\n        if (jobs == null)\n        {\n            throw new ArgumentNullException(nameof(jobs));\n        }\n\n        // Sort jobs by their end time (earliest finish first)\n        var sortedJobs = jobs.OrderBy(j => j.End).ToList();\n        var result = new List<Job>();\n        int lastEnd = int.MinValue;\n\n        foreach (var job in sortedJobs)\n        {\n            // If the job starts after the last selected job ends, select it\n            if (job.Start >= lastEnd)\n            {\n                result.Add(job);\n                lastEnd = job.End;\n            }\n        }\n\n        return result;","sourceCodeStart":4,"sourceCodeEnd":40,"githubUrl":"https://github.com/TheAlgorithms/C-Sharp/blob/96e2905cab7bc6b33ac0a34ee5bb82ddccbcbb6c/Algorithms/Problems/JobScheduling/IntervalSchedulingSolver.cs#L4-L40","documentation":"IntervalSchedulingSolver.Schedule throws ArgumentNullException when the jobs parameter is null. The greedy earliest-finish-first algorithm needs the job collection to select a maximal non-overlapping set.","triggerScenarios":"Calling Schedule(null), or passing a nullable IEnumerable<Job> that is null when no jobs were loaded.","commonSituations":"A repository/query returned null instead of an empty list; optional job input not initialized before scheduling; LINQ FirstOrDefault-style call returning null.","solutions":["Pass an empty collection instead of null: Schedule(Enumerable.Empty<Job>()).","Coalesce at the call site: jobs ?? Enumerable.Empty<Job>().","Fix the data-loading path that returned null rather than an empty sequence."],"exampleFix":"// before\nList<Job> jobs = LoadJobs(); // may be null\nvar selected = IntervalSchedulingSolver.Schedule(jobs);\n// after\nvar selected = IntervalSchedulingSolver.Schedule(LoadJobs() ?? Enumerable.Empty<Job>());","handlingStrategy":"type-guard","validationCode":"if (jobs is null) jobs = Enumerable.Empty<Job>();","typeGuard":"static bool HasJobs(IEnumerable<Job>? jobs) => jobs != null;","tryCatchPattern":"try { selected = IntervalSchedulingSolver.Schedule(jobs); }\ncatch (ArgumentNullException) { selected = new List<Job>(); }","preventionTips":["Return empty collections, never null, from loaders","Coalesce with ?? Enumerable.Empty<Job>()","Enable nullable annotations on job-loading APIs"],"tags":["null-argument","interval-scheduling","argument-null"],"backgroundTag":"null-argument","analyzedSha":"96e2905cab7bc6b33ac0a34ee5bb82ddccbcbb6c","analyzedAt":"2026-09-13T17:04:01.438Z","contentChangedAt":"2026-09-13T17:04:01.438Z","schemaVersion":2},"datasetVersion":"2026-09-16T09:17:16.951Z"}