© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
C#C
C#•3y ago•
27 replies
Will Pittenger

✅ Null check not enough to safely convert from nullable enum

I have a class declaring an
enum
enum
and a nullable value for that
enum
enum
:
public readonly StdModeTypes? smt;
public readonly StdModeTypes? smt;

I then try to reference that field from a second class:
if(cmodeCur.smt != null)
    mapModesWithStdTypes[cmodeCur.smt] = cmodeCur;
if(cmodeCur.smt != null)
    mapModesWithStdTypes[cmodeCur.smt] = cmodeCur;

Yet even with the null check, the IDE is insisting that
smt
smt
could be
null
null
and won't let me use the value:
Error    CS1503    Argument 1: cannot convert from 'BestChat.IRC.Data.Defs.ChanMode.StdModeTypes?' to 'BestChat.IRC.Data.Defs.ChanMode.StdModeTypes'
Error    CS1503    Argument 1: cannot convert from 'BestChat.IRC.Data.Defs.ChanMode.StdModeTypes?' to 'BestChat.IRC.Data.Defs.ChanMode.StdModeTypes'

What's going on?
C# banner
C#Join
We are a programming server aimed at coders discussing everything related to C# (CSharp) and .NET.
61,871Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements

Similar Threads

✅ Convert Enum to string
C#CC# / help
4y ago
Null check
C#CC# / help
15mo ago
❔ Converting null iteral or possible null value to non-nullable type
C#CC# / help
3y ago
Converting null literal or possible null value to non-nullable type.
C#CC# / help
2y ago