✅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
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.
2 Replies
gp.Sum(x => x.Quantidade.Value)
will never be null
you're testing if it's not null, so it's warning you that the test will always evaluate to true
unless this is EF Core or something translating the expression to SQL, in which case yeah the compiler warnings aren't really applicable so i'd just disable itI understand, this is in a query and I'm using EF Core, so I believe this is exactly what you mentioned. Because there were cases that returned null