Is there a ?= conditional assignment operator in C#? #8599
Replies: 6 comments 25 replies
-
There is not an operator like that, no. |
Beta Was this translation helpful? Give feedback.
-
What's the harm in setting a property/field to the same value? If this has something to do with reactive components, you can implement the |
Beta Was this translation helpful? Give feedback.
-
I don't like the idea of such an operator for property access. It hides that you are performing both a read and a write operation, and it is inherently not thread safe. |
Beta Was this translation helpful? Give feedback.
-
A single compound assignment operator is not a compound use of operators at the source level, such as Maybe chaining is a better term, but a compound operator that performs multiple operations internally isn't what I was describing above. |
Beta Was this translation helpful? Give feedback.
-
Thankfully, you won't see these sorts of debates in the LISP world.
|
Beta Was this translation helpful? Give feedback.
-
I disagree. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Another language I use, has the operator ?= which basically assigns a value to a property/field if that property/field's current value is != to the value to be assigned. If they are equal, nothing happens.
IOW,
x ?= 10;
Is equivalent to
if(x != 10) x = 10;
I've searched the language spec and see nothing like it, and am just wondering if it exists possibly using a different form.
I deal with properties that trigger significant work on assignment and in some cases, they don't do the check internally before doing all that work.
Beta Was this translation helpful? Give feedback.
All reactions