✅ Null check not enough to safely convert from nullable enum
I have a class declaring an
enum
and a nullable value for that enum
:
I then try to reference that field from a second class:
Yet even with the null check, the IDE is insisting that smt
could be null
and won't let me use the value:
What's going on?20 Replies
Given the
smt
field is readonly
, isn't that enough to ensure the value hasn't changed?With value types the nullability is different
With ref types it is just an annotation, more or less
OK.
But with value types it is an actual type, in your case Nullable<StdModeTypes>
Too bad the compiler doesn't automatically unwrap it for you when the value can't be
null
.
.HasValue is the same as
!= null
or is not null
In this case
This is also an option if you like patternsUnknown User•13mo ago
Message Not Public
Sign In & Join Server To View
I have the ultimate solution for this
Unknown User•13mo ago
Message Not Public
Sign In & Join Server To View
PHP
That command had an error
UnknownCommand: Unknown command.
Remove your reaction to delete this message
$bam
User bammed successfully.
Unknown command
$bam @Hin
User bammed successfully.
Bam?
Unknown User•13mo ago
Message Not Public
Sign In & Join Server To View
Yup
Unknown User•13mo ago
Message Not Public
Sign In & Join Server To View
Yes. Thanks. Used to classes.