Advertisement
Intermediate C#, Nullable Reference Types

How do nullable annotations affect API design?

Short answer

Method signatures document intent: a string? parameter accepts null, a string return promises non-null. This forms a contract callers can rely on.

Save C# mock interview
Advertisement
AModel answer
Method signatures document intent: a string? parameter accepts null, a string return promises non-null. This forms a contract callers can rely on.
public User? FindById(int id);   // may return null
public string GetName(User u);   // never null
Real-world example
A repository returning User? signals to callers they must handle 'not found'.