Add lifted operator support for nullable decimals #3973
-
Hi, I have a half-baked proposal, but maybe it'd be too much of a breaking change. Given the following code:
I think that many people might expect the answer to be 2, with type nullable decimal. Instead as there's no lifted operator it returns null. Could this behavior be considered, or is this too much of a change to the language at this point? Thanks, |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 3 replies
-
This is the case with all of the nullable types and it is on purpose. |
Beta Was this translation helpful? Give feedback.
-
> int? a = 1;
> int? b = null;
> a + b
null The lifting rule is consistent among types. Arithmetic operation for any |
Beta Was this translation helpful? Give feedback.
-
Isn't that still the same in SQL?
1 + null = null, but SUM(column) where column = nullable int ignores nulls ?
…On Mon, 5 Oct 2020 at 14:03, HaloFour ***@***.***> wrote:
I don't think I noticed that before but it doesn't surprise me. When
nullable value types were added in .NET 2.0 there wasn't really a
prescribed way for handling binary operators between them. C# and VB.NET
differed in their implementations from the outset. As LINQ was introduced
later in .NET 3.5 as an API it had to choose an implementation that would
apply across all languages.
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
<#3973 (reply in thread)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/ADIEDQIFVKP5SWUU7EESE6DSJG7ZPANCNFSM4SETYL6Q>
.
|
Beta Was this translation helpful? Give feedback.
This is the case with all of the nullable types and it is on purpose.
null
is not the same as0
, it's treated more like "unknown", like NULL in SQL. Changing that would be a breaking change.