Proposal: !! operator #3103
Replies: 8 comments
-
If it's just a longCamelCasedVariableName ^= true; |
Beta Was this translation helpful? Give feedback.
-
This is very much nothing like ++ and --. That would imply the -- was two negations. |
Beta Was this translation helpful? Give feedback.
-
I would never want |
Beta Was this translation helpful? Give feedback.
-
Don't forget that a |
Beta Was this translation helpful? Give feedback.
-
Since #186, C# 7.2 also allows |
Beta Was this translation helpful? Give feedback.
-
I'll one up you. I want a if (!!!!areThereCookies()) eatCookies(); |
Beta Was this translation helpful? Give feedback.
-
While I don't agree with syntax at all I think it is interesting reason for the feature Maybe, what if we could write a shorthand like this? bool longCamelCasedVariableName = false;
// .. later in code ...
longCamelCasedVariableName = !; // just symbol ! for shorthand the whole left side variable
someClass.someProperty.someValue.someBoolean = !; // also work with deep variable |
Beta Was this translation helpful? Give feedback.
-
If you shout at a boolean it will flip its..! ...value... |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
In the same fashion of the ++ or -- operators, there should be a !! operator for the cases when we want to flip a boolean without having to self-reassign it. This is especially nice in practice when using long camel-cased variable names. Because instead of looking for a ! in the midst of a long code line, we can much more easily identify !! at the end and recognize its importance.
This instead would be written as:
Beta Was this translation helpful? Give feedback.
All reactions