Skip to content

Null Operators

Mario Gutierrez edited this page Jan 7, 2017 · 7 revisions

Null Coalescing Operator (??)

Returns an alternate value on null.

Card cardB = cardA ?? new Card("2C"); // If cardA is null, return new Card.

Null Conditional Operator (?.)

Provides safe method access. Also known as "Elvis operator."

Card cardA = deckA?.Get(1);

If deckA turns out to be null, it will return null and not call Get().

Clone this wiki locally