© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
C#C
C#•3y ago•
8 replies
ingovals

❔ What could cause the compiler to not infer this nullability correctly

        if (pageNumber.HasValue)
        {
            query["PageNumber"] = pageNumber.ToString();
        }
        if (pageNumber.HasValue)
        {
            query["PageNumber"] = pageNumber.ToString();
        }


I get the warning here about possible null reference, but it is pretty obvious that this could be inferred by flow analysis.
I'm assuming something is wrong, old codebase, old compile etc. I just don's use .net as much anymore and I haven't kept up.
What should I look at?
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

❔ Compiler cannot infer lambda return type
C#CC# / help
3y ago
❔ Nullability issue
C#CC# / help
3y ago
❔ EF Core nullability vs API nullability behavior
C#CC# / help
4y ago
What could I do to make this neater?
C#CC# / help
2y ago