Skip to content
CShift0.32

Optional<T>

Struct · built-in type

struct Optional<T>

A value or nothing (null): the result of a search that can find nothing.

Optional<User> FindUser(int id) { ... return null; }
if (FindUser(7) is User u)
Console.WriteLine(u.Name);

An Optional<T> is not a condition: test it with is T v, is null, == null or switch. A T converts to it. See the language guide (error handling).