Skip to main content

Practice · 3 of 4

Null-state gate

CHALLENGE
Difficulty: advanced+25 XP

Implement static int LengthOrMinus(string? text): return -1 when text is null, else its Length. Then implement static string Coalesce(string? a, string? b): first non-null of a and b, or "<empty>". The tests exercise the null-state contract with nullable reference types in mind.

Back to lesson: Practice: Semantics under the microscope