Skip to main content
← Back to Code Arena
Easy Apprentice DebugIt nullability linq debugging

Debug It: The Mysterious NullReferenceException

+120 XP · 10 min · attempt 1

Problem

The following method throws NullReferenceException at runtime when called with an empty list. What is the name of the LINQ method (single word, exactly as it appears in System.Linq) that should be replaced or guarded against to fix the bug?

  public static int GetTopScore(List<int> scores)
  {
      return scores.OrderByDescending(s => s).First();
  }

Replace the unsafe call with its safe equivalent. Enter the unsafe method name.

Starter

public static int GetTopScore(List<int> scores)
{
    return scores.OrderByDescending(s => s).First();
}

Your answer

Log in to submit