You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Here's a situation I've run into before: given an optional array, return one more than its length if it's defined, and some fallback value (e.g. 0) if it isn't. Currently this can be done in two ways:
The first one is a little verbose, especially if it's embedded in a longer expression. The second one is less obvious why it works, and doesn't easily accommodate a configurable fallback value.
C#'s mathematical operators are optional-chained by default, so this can be written as
intLengthPlusOne(List<int>?l)=> l?.Count +1??0;
While we can't change the behavior of the existing JS operators -- after all, null + '' is still meaningful -- it would be nice for there to be a syntax for this, e.g. ?+.
The text was updated successfully, but these errors were encountered:
If assignment operators are included in this, the behavior it would imply for ?= is the exact opposite of its current behavior.
Less of an observation and more of a question: does it make sense to extend this to unary operators? x?++ is reminiscent of optional index access / calls, but ?-x looks a little strange.
Related: #897
Here's a situation I've run into before: given an optional array, return one more than its length if it's defined, and some fallback value (e.g. 0) if it isn't. Currently this can be done in two ways:
The first one is a little verbose, especially if it's embedded in a longer expression. The second one is less obvious why it works, and doesn't easily accommodate a configurable fallback value.
C#'s mathematical operators are optional-chained by default, so this can be written as
While we can't change the behavior of the existing JS operators -- after all,
null + ''
is still meaningful -- it would be nice for there to be a syntax for this, e.g.?+
.The text was updated successfully, but these errors were encountered: