How to declare Nullable property #6227
-
I just wondering. private object _obj;
[DisallowNull]
public object? OBJ
{
get => _showOBJ ? _obj : null; // May return null
set => _obj = value; // Must not be null
} private object _obj;
[MaybeNull]
public object OBJ
{
get => _showOBJ ? _obj : null; // May return null
set => _obj = value; // Must not be null
} |
Beta Was this translation helpful? Give feedback.
Answered by
huoyaoyuan
Jun 19, 2022
Replies: 1 comment 1 reply
-
The guideline used in runtime repo: https://github.com/dotnet/runtime/blob/main/docs/coding-guidelines/api-guidelines/nullability.md#nullable-attributes TL; DR: |
Beta Was this translation helpful? Give feedback.
1 reply
Answer selected by
FaustVX
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The guideline used in runtime repo: https://github.com/dotnet/runtime/blob/main/docs/coding-guidelines/api-guidelines/nullability.md#nullable-attributes
TL; DR:
DisallowNull
is preferred overMaybeNull
.