© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
C#C
C#•17mo ago•
4 replies
xandyMelo

✅wrong warning

I came across a case where the C# extension in visual studio code generated the warning: The result of the expression is always 'true' since a value of type 'decimal' is never equal to 'null' of type 'decimal?'CS0472
code below
var aux = query
                .GroupBy(x => x.Data)
                .Select(gp => new Metrics
                {
                    Data = gp.Key.Date,
                    // #pragma warning disable CS0472
                    OrganicTrash = gp.Sum(x => x.Quantidade.Value) != null ? gp.Sum(x => x.Quantidade.Value) : 0
                    // #pragma warning restore CS0472
                }).ToList();
            
            return aux;
var aux = query
                .GroupBy(x => x.Data)
                .Select(gp => new Metrics
                {
                    Data = gp.Key.Date,
                    // #pragma warning disable CS0472
                    OrganicTrash = gp.Sum(x => x.Quantidade.Value) != null ? gp.Sum(x => x.Quantidade.Value) : 0
                    // #pragma warning restore CS0472
                }).ToList();
            
            return aux;

It turns out that OrganicTrash was returning null in cases where quantity was null. I know I can use pragma to stop the warning, but I was curious if I could try to fix this, I took a look at the repository and I'm thinking that I'll actually need to work on the roslyn repository. Any opinions? I'm a beginner and looking for more experienced opinion.
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

❔ Windows Warning
C#CC# / help
3y ago
possible null reference warning
C#CC# / help
2y ago
Co-varient array warning.
C#CC# / help
3y ago
✅ whats wrong
C#CC# / help
2y ago