-
Notifications
You must be signed in to change notification settings - Fork 1
Null Operators
Mario edited this page Sep 6, 2024
·
7 revisions
Returns an alternate value on null.
??
Card cardB = cardA ?? new Card("2C"); // If cardA is null, return new Card.
Provides safe method access. Also known as "Elvis operator."
?.
and ?[]
Card cardA = deckA?.Get(1);
Card cardB = deckA?[2];
If deckA
turns out to be null, it will return null and not call Get()
or do the array access.
CAUTION FOR UNITY ENGINE PROGRAMMERS: This style of null check does not work on Unity.Object objects such as GameObject or MonoBehaviours as those override the equality operators to do a custom null check instead of the object itself becoming null!
- Abstract Classes
- Access Modifiers
- Anonymous Methods
- Anonymous Types
- Arrays
- Attributes
- Console I/O
- Constructors
- Const Fields
- Delegates
- Enums
- Exceptions
- Extension Methods
- File IO
- Generics
- Interfaces
- Iterators
- LINQ
- Main
- Null Operators
- Parameters
- Polymorphism
- Virtual Functions
- Reflection
- Serialization
- Strings
- Value Types
- "Base" Keyword
- "Is" and "As"
- "Sealed" Keyword
- nameof expression